Learn how to a build a cloud-first strategyRegister Now


imagecreatefrompng() fatal errors

Posted on 2006-05-08
Medium Priority
Last Modified: 2012-05-05
I can't say that I've worked extensively with the GD library, but I've been toying with some of those functions tonight, and unfortunately the imagecreatefrompng() function throws back a fatal warning:

Warning: imagecreatefrompng(): '/home/gmyers/public_html/test.png' is not a valid PNG file in /home/gmyers/public_html/tester.php on line 2

I'm pretty sure it is *valid*; I just created it in Photoshop CS. Although I'm not sure in this case what PHP's definition is valid is. I also tested the function getimagesize() on the same image, which worked successfully; it gave me the correct width × height. The image has a transparent background, probably has a lot of colors, and may have some alpha blending (I used the polygon lasso tool in Photoshop to cut out the background; I believe that may cause the edges to have partial transparency.) I know that those properties may be causing the problem with PHP, and if that's the case, is there some way to preserve transparency/alpha channels? If that's not the case, what did I screw up?

Code I'm using:

$old_image = imagecreatefrompng('/home/gmyers/public_html/test.png');
$new_image = imagecreatetruecolor(400, 150);

imagecopy($new_image, $old_image, 0, 0, 130, 0, 100, 100);

header('Content-type: image/png');
Question by:soapergem
  • 2
LVL 40

Accepted Solution

Richard Quadling earned 2000 total points
ID: 16637470
Can you give a URL to the image?

Author Comment

ID: 16637544
Heh...don't I feel silly now. It turns out that when I uploaded the image, my FTP client encountered an error and only partially uploaded it. That would be the problem! I've re-uploaded, and it works fine now. Aside from that, I'm a generous guy, and I think I would have been beating myself over the head for quite awhile longer had you not said that comment, so I'm going to give you all the points. Thanks!
LVL 40

Expert Comment

by:Richard Quadling
ID: 16637553

The next thing I would have done is downloaded the image and then tried running the script myself.

But as soon as the URL failed ...

Thanks anyway.

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month20 days, 18 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question