Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 413
  • Last Modified:

imagecreatefrompng crashes

i create a smaller version of image and save it, but any time i use imagecreatefrompng() it crashes.  

the smaller image is created, but there is no preview or it wont open and the imagedestroy() dont get executed resulting in me not able to delete image.

any idea's?  

ive noticed it dont actually write any bytes to new image..
0
ellandrd
Asked:
ellandrd
  • 7
  • 4
1 Solution
 
snoyes_jwCommented:
There is an open bug report (http://bugs.php.net/bug.php?id=29482) which suggests the problem is a corrupt or broken image.  Try opening the image in a different editor and saving as a new file.
0
 
ellandrdAuthor Commented:
>>Try opening the image in a different editor and saving as a new file.

not possible, when the users of the website upload their PNG images, thats that, i wont be touching the image and the users, once they've uploaded their image, wont be able to touch it either, other than viewing it in their profile setting...

its not an option to upload as PNG and save as JPEG as im not allowed do that...

is the corrupt or broken image caused from the function?
0
 
snoyes_jwCommented:
I'd still try re-saving the image, just to see if that's the problem.  If it is, you could create some script to run every image through imagemagick or some such in order to "clean it up" before PHP tries to mess with it.

I assume from the bug report and your description that the image was broken before it got to PHP.  But you'd be the better judge of that than I, since you know what functions you'be put the image through before you get the error.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ellandrdAuthor Commented:
here is my code:

$info = getimagesize( $uploadedfile ) ;
$newwidth = 180 ;
$newheight = ( $info[ 1 ] / $info[ 0 ] ) * 180 ;
$src = imagecreatefrompng( $uploadedfile ) ;
$tmp = imagecreatetruecolor( $newwidth, $newheight ) ;
imagecopyresized( $tmp, $src, 0, 0, 0, 0, $newwidth, $newheight, $info[ 0 ], $info[ 1 ] ) ;
imagepng( $tmp, $directory . $newThumbnailImagename, 100 ) ;
imagedestroy( $src ) ;
imagedestroy( $tmp ) ;
0
 
snoyes_jwCommented:
And it crashes at the line
$src = imagecreatefrompng( $uploadedfile ) ;
?
0
 
ellandrdAuthor Commented:
>>I assume from the bug report and your description that the image was broken before it got to PHP.

No, no, no

when the process is over, i should have the original uploaded PNG, and thumbnail version of the original PNG.

the code above is my code to resize original PNG and save it.

the PNG that i just upload (dont manipulate it in any shape or form) uploads fine and keeps all contents and opens fine.

its the resized image im having problems with.  the resized image is created in terms of a object named "thumbnail_image1.png" is visible in my media folder, but when i click/highlight it, i get "no preview available" or if i try opening it, fireworks cant open it.

the message from fireworks is "could not open the file - an internal error occurred"...
0
 
ellandrdAuthor Commented:
>>And it crashes at the line
>>$src = imagecreatefrompng( $uploadedfile ) ;
>>?

yes! i have placed echo statements before and after it and i can only see the before echo statement..
0
 
ellandrdAuthor Commented:
sorry my mistake - it crashes here:

imagepng( $tmp, $directory . $newThumbnailImagename, 100 ) ;

sorry...
0
 
snoyes_jwCommented:
Is this on Windows?  I found someone else with the same problem.  Their solution was to replace the GD dll.
http://www.interaktonline.com/Products/Dreamweaver-Extensions/MXDynamicCharts/Product-Forum/Details/78629/fatal+libpng+error+in+Dynamic+Charts.html?last=1
0
 
ellandrdAuthor Commented:
got it working...

cheers

code:

echo "here1";
                        $src = imagecreatefrompng($uploadedfile);
                        $tmp = imagecreatetruecolor($newwidth, $newheight);
                        imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$info[ 0 ],$info[ 1 ]);
                        echo "here2";
                        imagesavealpha( $tmp, true ) ;
                        //$tmp = imagetruecolortopalette($tmp,false,255);
                        echo "here3";
                           imagepng($tmp,$directory.$newThumbnailImagename);
                        echo "here4";
0
 
ellandrdAuthor Commented:
im on apache 2.2.2 using php 5.2.0 and the fuc*ing php_gd.dll was the issue...

why dont the developers test all dll's proper! i hate - its the same with the php_java.ar extension in there latest build... i found a bug in it the other and its still not fixed either... resulting in me not being able to create a new java object in php...

annoying!

anyways cheers!

ellandrd
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now