tags:

views:

894

answers:

4

I have a image upload form that should take image types (PNG, JPEG, GIF), resize it and then save it to a path.

For some reason I can't get the PNG file types to work, it works fine with JPEG/GIF and the file is copied so it looks like it's something to do with how I'm creating the PNG.

Does PNG creation in PHP require different parameters or options? Some sample code of lines that do image creation:

$src = imagecreatefrompng($uploadedfile); imagecreatetruecolor($newWidth,$newHeight) imagecopyresampled($tmp,$src,0,0,0,0,$newWidth,$newHeight,$width,$height); imagepng($tmp,$destinationPath."/".$destinationFile,100);

The same commands work for JPG and GIF... any ideas?

+2  A: 

You need to look how your PHP is built.. Eg:

GD Support  enabled
GD Version  bundled (2.0.28 compatible) 
PNG Support     enabled

If you don't have PNG support compiled in, you'll need to have that updated.

DreamWerx
checked and I have PNG support:'GIF Read Support' => boolean true 'GIF Create Support' => boolean true 'JPG Support' => boolean true 'PNG Support' => boolean truethanks for the reply though... thought that would be it
A: 

Are you starting with PNG-8 images? There are some issues with PNG-8 vs PNG-24 when working with PHP. Make sure PNG support is compiled in, then take a look at this persons solution to the PNG-8 problem.

Chris Bartow
I tried both 8 and 24 bit and it doesn't make a difference. Seems like something is wrong with imagepng().If I just use imagejpeg() on a png, it actually works okay...
A: 

checked and I have PNG support:

'GIF Read Support' => boolean true 'GIF Create Support' => boolean true 'JPG Support' => boolean true 'PNG Support' => boolean true

thanks for the reply though... thought that would be it

+1  A: 

I figured out the problem, just a problem of me not reading the API :P.

unlike imagejpg() or imagegif(), imagepng() accepts an integer of 0-9 for compression. so I was passing 100 as a parameter thinking the quality would be higher but instead I guess I treated it as maximum compression. Passing 0 solved the problem.

Maybe the API has changed from php versions?