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 and line no. 43 and added the line 44:header("content-type:image/png.jpeg.");
But then I started getting the following error :
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in c:\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 full code:
I am getting the error from this line -HTML 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); ?>
HTML Code:putenv('GDFONTPATH=C:\WINDOWS\Fonts');



Reply With Quote
Bookmarks