andre
andre

Reputation:

PNG Creation in PHP (is it different than gif and jpg?)

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.

Upvotes: 0

Views: 2063

Answers (4)

andre
andre

Reputation:

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?

Upvotes: 1

andre
andre

Reputation:

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

Upvotes: 0

Chris Bartow
Chris Bartow

Reputation: 15111

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.

Upvotes: 0

DreamWerx
DreamWerx

Reputation: 2909

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.

Upvotes: 2

Related Questions