36pixels Posted July 29, 2012 Share Posted July 29, 2012 (edited) 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. Then I commented line no. 15 and line no. 43 and added the line 44:header("content-type:image/png.jpeg."); But now I get the error : Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in I:\xampp\htdocs\test\button\make_button.php on line 21Could 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 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>8 && ($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);?> Edited July 29, 2012 by 36pixels Link to comment Share on other sites More sharing options...
birbal Posted July 29, 2012 Share Posted July 29, 2012 Warning: imagecreatefrompng(red-button.png) [function.imagecreatefrompng]: failed to open stream: No such file or directory.that means the file does not exist which you are tryig to open header("content-type:image/png.jpeg.");that is not correct header, you can use image/png or image/jpeg Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in I:\xampp\htdocs\test\button\make_button.php on line 21 that is parse error or syntax error.here you can find how to handle different type of errorhttp://w3schools.invisionzone.com/index.php?showtopic=44473 Link to comment Share on other sites More sharing options...
36pixels Posted July 29, 2012 Author Share Posted July 29, 2012 (edited) Hi birbal,Thanks for reply but that is not where i am getting error from.In fact I already tried this out- header("content-type:image/png"); But still I am getting the error and specifically the line is - putenv('GDFONTPATH=c:\windows\fonts'); Edited July 29, 2012 by 36pixels Link to comment Share on other sites More sharing options...
36pixels Posted July 29, 2012 Author Share Posted July 29, 2012 (edited) Birbal your explnations are always a little vague and insuffiecient.Can you pls elucidate more detail?I will be vry greatful if you or someone else can help me. Edited July 29, 2012 by 36pixels Link to comment Share on other sites More sharing options...
birbal Posted July 29, 2012 Share Posted July 29, 2012 (edited) you did not specify which line is 21,41 or 45. you asked about errors and answer is the above.general question have general answers. you have to give us enough information so that we can help you more precisely. But still I am getting the error and specifically the line is -putenv('GDFONTPATH=c:\windows\fonts');what error is it showing? it is not giving any parse error by the way. Edited July 29, 2012 by birbal Link to comment Share on other sites More sharing options...
36pixels Posted July 29, 2012 Author Share Posted July 29, 2012 (edited) Yes I am getting parse error!!I already mentioned the error right in the begining of this post,still i repeat itParse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in I:\xampp\htdocs\..\..\button\make_button.php on line 21Also line 21 is this code above - putenv('GDFONTPATH=c:\windows\fonts'); Edited July 29, 2012 by 36pixels Link to comment Share on other sites More sharing options...
birbal Posted July 29, 2012 Share Posted July 29, 2012 i ran your code, it is not giving any parse error. Link to comment Share on other sites More sharing options...
36pixels Posted July 29, 2012 Author Share Posted July 29, 2012 How can that be possible!!Either you are joking with me or you must have changed the code somewhere!!Then give me your code please Link to comment Share on other sites More sharing options...
birbal Posted July 29, 2012 Share Posted July 29, 2012 i just pasted your code and have not changed anything. it is not giving any parse error though it is throwing some runtime error like notices and warning but not the parse error. Link to comment Share on other sites More sharing options...
36pixels Posted July 29, 2012 Author Share Posted July 29, 2012 But are the buttons displaying as it should? Link to comment Share on other sites More sharing options...
birbal Posted July 29, 2012 Share Posted July 29, 2012 yes it is also visible. make sure you are running the correct file and clear your caches. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now