Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18

Thread: parse error

  1. #1
    Regular Coder
    Join Date
    Jun 2011
    Posts
    119
    Thanks
    43
    Thanked 0 Times in 0 Posts

    parse error

    Hi, I am trying to learn php and when I feel i understand a concept I like to try it out by writing a script or two. I am currently attempting to create an image on the fly, like a button. I kept receiving the message:
    Warning: imagecreatefrompng(red-button.png) [function.imagecreatefrompng]: failed to open stream: No such file or directory.
    But the error was gone when I commented a few lines to check then removed it ,pls check in your editor most probably -- line no. 15
    Code:
    putenv('GDFONTPATH=C:\WINDOWS\Fonts')
    which I later removed the comment from and then line no. 43 and added the line 44:header("content-type:image/png.jpeg.");

    But now I get the follwing error :
    Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in I:\xampp\htdocs\web\button\make_button.php on line 21

    Could someone please take a look at this for me and tell me what you think I've done wrong?? I would really appreciate it, I've looked at it until my eyes have about gone on strike. Here is the complete code:
    PHP Code:
    <form name ="button" action ="make_button.php" method="post">
    <input type ="text" name = "button_text">
     
    <p>
    <label>
    <input type="radio" name="color" value="red" id="red">
    Red</label>
     
    <label>
    <input type="radio" name="color" value="green" id="green">
    Green</label>
     
    <input type="radio" name="color" id="blue" value="blue">
    Blue</label>
    </p>
     
    <input type ="submit" name ="submit" value ="CREATE!">
    </form>
     
    <?php
    $button_text
    =$_POST['button_text'];
    $color=$_POST['color'];
     
    if(empty(
    $button_text)||empty($color))
    {
    echo 
    'Could not create image - form not filled out correctly';
    exit;
    }
     
    $im=imagecreatefrompng('\button'.$color.'-button.png');
     
    $width_image=imagesx($im);
    $height_image=imagesx($im);
     
    $width_image_wo_margins=$width_image-(2*18);
    $height_image_wo_margins=$height_image-(2*18);
     
    $font_size=33;
     
    putenv('GDFONTPATH=C:\WINDOWS\Fonts');
    $fontname='arial';
    do
    {
            
    $font_size--;
     
            
    $bbox=imagettfbbox($font_size,0,$fontname,$button_text);
            
    $right_text=$bbox[2];
            
    $left_text=$bbox[0];
            
    $width_text=$right_text $left_text;
            
    $height_text=abs($bbox[7]-$bbox[1]);
    }
    while(
    $font_size>&& ($height_text>$height_image_wo_margins||$widht_text>$width_image_wo_margins));
    if(
    $height_text>$height_image_wo_margins||$widht_text>$width_image_wo_margins)
    {
            echo 
    'Text given will not fit on button.<br>';
    }
    else
    {
            
    $text_x=$width_image/2.0-$width_text/2.0;
            
    $text_y=$height_image/2.0-$height_text/2.0;
      
            if(
    $left_text<0)
                    
    $text_x+=abs($left_text);
            
    $above_line_text=abs($bbox[7]);
    $text_y +=$above_line_text;
    $text_y -=2;
    $white=imagecolorallocate($im,255,255,255);
    imagettftext($im,$font_size,0,$text_x,$text_y,$white,$fontname,$button_text);
    //header('Content-type:image/png');
    header("content-type:image/png.jpeg.");
     
    imagepng($im);
    }
    imagedestroy($im);
    ?>
    In fact it is this line -->
    Code:
    putenv('GDFONTPATH=C:\WINDOWS\Fonts');
    that is giving the parrse error. Is the syntax wrong?
    Last edited by ippo; 07-29-2012 at 11:03 AM.

  • #2
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,974
    Thanks
    15
    Thanked 229 Times in 229 Posts
    PHP Code:
    $fpath="C:\WINDOWS\Fonts";
    putenv('GDFONTPATH=$fpath'); 
    It seems to like that syntax, so try that.

  • #3
    Regular Coder
    Join Date
    Jun 2011
    Posts
    119
    Thanks
    43
    Thanked 0 Times in 0 Posts
    Hi DrDOS,
    I tried that already still I did as per your suggestion again and I get a parse on this line :
    Parse error: syntax error, unexpected T_STRING on line 17.

    Line 17 reads :
    PHP Code:
     $fpath="C:\WINDOWS\Fonts"

  • #4
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Try

    PHP Code:
    $fpath="C:\\WINDOWS\\Fonts"
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #5
    Regular Coder
    Join Date
    Jun 2011
    Posts
    119
    Thanks
    43
    Thanked 0 Times in 0 Posts
    Hi Andrew,
    Still the same error:
    Parse error: syntax error, unexpected T_STRING in line 17( $fpath="C:\\WINDOWS\\Fonts";
    )

  • #6
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    The error is probably earlier in the code. This

    Code:
    <input type="radio" name="color" id="blue" value="blue">
    Blue</label>
    has no opening label tag.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #7
    Regular Coder
    Join Date
    Jun 2011
    Posts
    119
    Thanks
    43
    Thanked 0 Times in 0 Posts

    Exclamation

    Hi Andrew,
    Sorry your are wrong again!! I forgot to mention that the first part in the above code is written in a different html page named "design_button.html"(Here I mentioned the 2 codes together for the sake of convenience.).
    Actually I have made 2 files inside my button folder viz.-- design_button.html & make_button.php.Also I have created 3 blank .png images in the same folder.

  • #8
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,974
    Thanks
    15
    Thanked 229 Times in 229 Posts
    Try escaping the semicolon, that's what the backslash does. If you run into trouble like that, try escaping different parts of the string. We all have to do that from time to time. The backslash escapes itself.

  • #9
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    .. I still think you need to look earlier in the code for an unescaped character or a missing $ sign
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #10
    Regular Coder
    Join Date
    Jun 2011
    Posts
    119
    Thanks
    43
    Thanked 0 Times in 0 Posts
    Hi AndrewGSW,
    Do you mean this-
    $fpath="C:\\WINDOWS\\Fonts"\;

    But the semicolon is outside the double-quotes!!so is there any need to escape it?
    So i think that is wrong!!
    Still,again i tried your suggestion & it was in vain!
    The same error I am getting as before in the same line number-
    Parse error: syntax error, unexpected T_STRING in line 17.
    line 17 reads -
    Code:
     $fpath="C:\\WINDOWS\\Fonts"\;
    Last edited by ippo; 07-30-2012 at 04:19 AM.

  • #11
    Regular Coder
    Join Date
    Jun 2011
    Posts
    119
    Thanks
    43
    Thanked 0 Times in 0 Posts
    I have tried all sorts of ways but in vain!!Again I post here my complete code for everyone's reference-
    PHP Code:
    <?php
    $button_text
    =$_POST['button_text'];
    $color=$_POST['color'];
    if(empty(
    $button_text)||empty($color))
    {
    echo 
    'Could not create image - form not filled out correctly';
    exit;
    }
    // $imgname="file:\\I:\xampp\htdocs\\test\\button\\";

    $imgname="I:\\xampp\\htdocs\\web\\button\\".$color."-button.png";
    $im=imagecreatefrompng($imgname);
    //$im=imagecreatefrompng("$imgname".$color."-button.png");
    $width_image=imagesx($im);
    $height_image=imagesx($im);
    $width_image_wo_margins=$width_image-(2*18);
    $height_image_wo_margins=$height_image-(2*18);
     
    $font_size=33;
     
    $fpath="C:\WINDOWS\Fonts";
    putenv("GDFONTPATH=$fpath");
    $font_name="arial";
    do
    {
            
    $font_size--;
     
    $bbox=imagettfbbox($font_size,0,$font_name,$button_text);
            
    $right_text=$bbox[2];
            
    $left_text=$bbox[0];
            
    $width_text=$right_text $left_text;
            
    $height_text=abs($bbox[7]-$bbox[1]);
    }while(
    $font_size>&& ($height_text>$height_image_wo_margins||$width_text>$width_image_wo_margins));

    if(
    $height_text>$height_image_wo_margins||$width_text>$width_image_wo_margins)
    {
            echo 
    "Text given will not fit on button.<br>";
    }
    else
    {
            
    $text_x=$width_image/2.0 $width_text/2.0;
            
    $text_y=$height_image/2.0 $height_text/2.0;
      
            if(
    $left_text<0)
                    
    $text_x+=abs($left_text);
            
    $above_line_text=abs($bbox[7]);
    $text_y  +=$above_line_text;
    $text_y  -=2;
    $white=imagecolorallocate($im,255,255,255);
    imagettftext($im,$font_size,0,$text_x,$text_y,$white,$fontname,$button_text);
    header("content-type:image/png");
    imagepng($im);
    }
    imagedestroy($im);
    ?>
    And now I am getting this errors
    Warning: imagecreatefrompng() [function.imagecreatefrompng]: 'I:\xampp\htdocs\test\button\blue-button.png' is not a valid PNG file in I:\xampp\htdocs\web\button\make_button.php on line 12
    Here are other errors that are coming up after it:
    Warning: imagesx() expects parameter 1 to be resource, boolean given in I:\xampp\htdocs\web\button\make_button.php on line 14

    Warning: imagesx() expects parameter 1 to be resource, boolean given in I:\xampp\htdocs\web\button\make_button.php on line 15

    Warning: imagettfbbox() [function.imagettfbbox]: Invalid font filename in I:\xampp\htdocs\web\button\make_button.php on line 25

    Please can anyone tell me where the error is?

    p.s:
    Line 12 is this :$im=imagecreatefrompng($imgname);
    Line 14 is this :$width_image=imagesx($im);
    Line 15 is this :$height_image=imagesx($im);
    Line 25 is this:$bbox=imagettfbbox($font_size,0,$font_name,$button_text);
    Last edited by ippo; 07-30-2012 at 05:48 AM.

  • #12
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Those warnings are all the same: 'blue-button.png' is not a valid .png file.

    Try using a different .png image to see if it is your image that is causing the problem.

    If so, try opening 'blue-button.png' in an image editor and save it explicitly as a .png file.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #13
    Regular Coder
    Join Date
    Jun 2011
    Posts
    119
    Thanks
    43
    Thanked 0 Times in 0 Posts
    Andrew,
    Can you please tell me how do I create the .png images?
    If I use paint say,then do i keep any button in the image file or the program will draw the button itself and I just need to create a blank .png file?

    p.s.:
    1)I did create 3 buttons called "red-button.png","blue-button.png" and "green-button.png" ,the red-button being 1x1 pixels height and width. Is the error due to its too small a size?
    2)Should I delete all three buttons?
    3)I thought that the buttons will be drawn by the program itself!!
    Last edited by ippo; 07-31-2012 at 03:04 AM.

  • #14
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,974
    Thanks
    15
    Thanked 229 Times in 229 Posts
    Is this site on a web server? If so you probably have some kind of image software available that will make any kind of blank file format you want, GD and Imagemagick are the two most common. If it's on you own server just install one of those and use it to make any image you want anytime.

  • #15
    Regular Coder
    Join Date
    Jun 2011
    Posts
    119
    Thanks
    43
    Thanked 0 Times in 0 Posts
    Why is it not possible to use Windows Paint Program to draw the buttons?
    Obviously I am using my own XAMPP server.
    Also I have installed Imagemagick 6.7.8(latest version) from their site and it has installed in the D:\Programs directory.Now I dont know which file i need to run & also where to run it from(I mean should I use cmd in windows run?)
    Please guide me as to how to run Imagemagick,or at least tell me which file I should Double click?

    p.s. : It has lots of folder and sub-folders like "coders","config","magick","magick++","www","utilities","script","m4","Wand" etc etc. There are lots of text-files as well!! I am confused even more !!
    OMG !! Just to create a simple button in PHP, do I have to take so much trouble!!
    BTW,I use Windows XP Pro and not linux!!Is it possible to run it in Winodws?
    Last edited by ippo; 07-31-2012 at 06:06 AM.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •