tivrfoa Posted January 30, 2009 Share Posted January 30, 2009 Hi! the following code doesn't working: <?php header("Content-type: image/png"); $string = $_GET['text']; $im = imagecreatefrompng("images/button1.png"); $orange = imagecolorallocate($im, 220, 210, 60); $px = (imagesx($im) - 7.5 * strlen($string)) / 2; imagestring($im, 3, $px, 9, $string, $orange); imagepng($im); imagedestroy($im); ?> I just copy and pasted it: http://php.net/manual/en/image.examples-png.php I created the folder images and added an image with the name "button1.png" and I'm passing the text parameter "php?text=text", but the page only display this: http://localhost/path/file.php?text=text Quote Link to comment https://forums.phpfreaks.com/topic/143152-solved-imagecreatefrompng-dont-work/ Share on other sites More sharing options...
premiso Posted January 30, 2009 Share Posted January 30, 2009 Note, localhost is local to your computer. We cannot see that. Copy what it displays, make sure you have the GD library installed. If it is an image that is displaying on the localhost take a screenshot and post it here. Quote Link to comment https://forums.phpfreaks.com/topic/143152-solved-imagecreatefrompng-dont-work/#findComment-750774 Share on other sites More sharing options...
tivrfoa Posted January 30, 2009 Author Share Posted January 30, 2009 Note, localhost is local to your computer. We cannot see that. i'm not that newbie . I think gd is installed, because I can create images, but not from png file. eg: <?php function LoadPNG($imgname) { /* Attempt to open */ $im = @imagecreatefrompng($imgname); /* See if it failed */ if(!$im) { /* Create a blank image */ $im = imagecreatetruecolor(150, 30); $bgc = imagecolorallocate($im, 255, 255, 255); $tc = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 150, 30, $bgc); /* Output an error message */ imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc); } return $im; } header('Content-Type: image/png'); $img = LoadPNG('bogus.image'); imagepng($img); imagedestroy($img); ?> this code enter in the "if", because it fails in create the image from the png file. Quote Link to comment https://forums.phpfreaks.com/topic/143152-solved-imagecreatefrompng-dont-work/#findComment-750779 Share on other sites More sharing options...
GingerRobot Posted January 30, 2009 Share Posted January 30, 2009 Note, localhost is local to your computer. We cannot see that. i'm not that newbie . Well why did you link to it then? lol. Anywho, i'm confused. Bogus.image obviously isn't a png image. So surely the script is performing correctly? Quote Link to comment https://forums.phpfreaks.com/topic/143152-solved-imagecreatefrompng-dont-work/#findComment-750789 Share on other sites More sharing options...
premiso Posted January 30, 2009 Share Posted January 30, 2009 Do a phpinfo I bet you that PNG Support is not enabled. And as far as my statement, sorry to implicate that, but you linking to it saying "It only displays this" sounded to me like you expect us to be able to click on it and see what you mean. Quote Link to comment https://forums.phpfreaks.com/topic/143152-solved-imagecreatefrompng-dont-work/#findComment-750791 Share on other sites More sharing options...
tivrfoa Posted January 30, 2009 Author Share Posted January 30, 2009 And as far as my statement, sorry to implicate that, but you linking to it saying "It only displays this" sounded to me like you expect us to be able to click on it and see what you mean. I didn't put the link to you access. I just write what displayed in the page, but as it start with "http:" it created the link automatically! Quote Link to comment https://forums.phpfreaks.com/topic/143152-solved-imagecreatefrompng-dont-work/#findComment-750796 Share on other sites More sharing options...
premiso Posted January 30, 2009 Share Posted January 30, 2009 I didn't put the link to you access. I just write what displayed in the page, but as it start with "http:" it created the link automatically! Sounds like you got some other issues, maybe with Apache....I do not know why it would show the url inside the page... ??? Anyhow did you checkout the phpinfo? Quote Link to comment https://forums.phpfreaks.com/topic/143152-solved-imagecreatefrompng-dont-work/#findComment-750800 Share on other sites More sharing options...
tivrfoa Posted January 30, 2009 Author Share Posted January 30, 2009 phpinfo(); .... gd GD Support enabled GD Version bundled (2.0.34 compatible) FreeType Support enabled FreeType Linkage with freetype FreeType Version 2.1.9 T1Lib Support enabled GIF Read Support enabled GIF Create Support enabled JPG Support enabled PNG Support enabled WBMP Support enabled XBM Support enabled ... I'm using IIS (not by my will). Maybe some access property, anyone? Quote Link to comment https://forums.phpfreaks.com/topic/143152-solved-imagecreatefrompng-dont-work/#findComment-750801 Share on other sites More sharing options...
premiso Posted January 30, 2009 Share Posted January 30, 2009 I'm using IIS (not by my will). Maybe some access property, anyone? Mmm, thats a pitty. I do not use IIS, I tested your script on my apache server and it worked like a champ....but I was using a 284x156 button1.png image, whether that has something to do with it I do not know. Quote Link to comment https://forums.phpfreaks.com/topic/143152-solved-imagecreatefrompng-dont-work/#findComment-750811 Share on other sites More sharing options...
tivrfoa Posted January 30, 2009 Author Share Posted January 30, 2009 I created some images in paint and saved as png, and it's all working fine. I was using some images that I saved as png from the Internet. thanks very much premiso Quote Link to comment https://forums.phpfreaks.com/topic/143152-solved-imagecreatefrompng-dont-work/#findComment-750864 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.