Jump to content
MakeWebGames

Recommended Posts

Posted (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 by lucky3809
Posted
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.

Posted
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

Posted (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 by lucky3809
Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...