Aaron Goff Aaron Goff - 2 years ago 138
PHP Question

Convert JPG/GIF image to PNG in PHP?

Possible Duplicate of

Convert jpg image to gif, png & bmp format using PHP

I have a PHP form that allows image uploads and checks
to make sure an image is valid.

However, I want all formats, PNG, JPG, JPEG, and GIF, to end up being PNG once submitted.

How can I go about doing this?

Answer Source

You just need imagepng() then. In fact it almost becomes a one-liner:

 imagepng(imagecreatefromstring(file_get_contents($filename)), "output.png");

You would use $_FILES["id"]["tmp_name"] for the filename, and a different output filename obviously. But the image format probing itself would become redundant.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download