lucky3809 Posted April 28, 2014 Posted April 28, 2014 (edited) SOLVED I am trying to use imagecreatefrompng() , but every image I put in it rather it is PNG or JPEG it does not recognize it, and throws an error of invalid png. This is the code I am using.. header ("Content-type: image/png"); $string = "Testing"; $font = 8; $width = imagefontwidth($font) * strlen($string); $height = imagefontheight($font) ; $im = imagecreatefrompng("test.png"); $x = imagesx($im) - $width; $y = imagesy($im) - $height; $backgroundColor = imagecolorallocate ($im, 255, 255, 255); $textColor = imagecolorallocate ($im, 0, 0,0); imagestring ($im, $font, $x, $y, $string, $textColor); imagepng($im); I have also tried the imagecreatefromstring() also as an other website stated, but same thing lol Also php info everything is enabled. Edited April 28, 2014 by lucky3809 Quote
sniko Posted April 28, 2014 Posted April 28, 2014 And test.png is a valid image on your server? Quote
lucky3809 Posted April 28, 2014 Author Posted April 28, 2014 That is what it is stating, but no on my server it is valid, but imagecreatefrompng() is stating it's invalid I changed the pics several times to different one and it still threw the error, I also path it from the direct path http://www.mydomain.com/test.png and nothing. Quote
sniko Posted April 28, 2014 Posted April 28, 2014 That is what it is stating, but no on my server it is valid, but imagecreatefrompng() is stating it's invalid I changed the pics several times to different one and it still threw the error, I also path it from the direct path http://www.mydomain.com/test.png and nothing. If test.png is not a valid image on your server, imagecreatefrompng will fail. Quote
lucky3809 Posted April 28, 2014 Author Posted April 28, 2014 test.png is valid though on server, but imagecreatefrompng is saying other wise. That is my problem. Quote
sniko Posted April 28, 2014 Posted April 28, 2014 test.png is valid though on server, but imagecreatefrompng is saying other wise. That is my problem. I apologize, I misread! What if you put the full path; /path/to/test.png Quote
lucky3809 Posted April 28, 2014 Author Posted April 28, 2014 (edited) This can be removed, I found a solution to this, that works the same!!! http://blog.doh.ms/2008/02/12/adding-text-to-images-in-real-time-with-php/ @Sniko, I have tried full path to it, I found 1 picture that allowed me to use it, but it was a blank white one, when I altered it, it than did not read the pic no longer for some reason. I used photoshop and paint and the end stayed png. Unless the code does not read pictures but only blank ones. Edited April 28, 2014 by lucky3809 Quote
ColdBlooded Posted April 29, 2014 Posted April 29, 2014 This is interesting. The tutorial and your proposed way of adding dynamic font text to image files became easier in new versions for php from what I did like 6 years ago with oldschool php. Nice Quote
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.