Denis Bobrovnikov
Denis Bobrovnikov

Reputation: 630

PHP Image Convert

In my web app users are allowed to upload images as their photos. How can I convert different image extensions to JPG? Input files are JPG, PNG or GIF.

Upvotes: 2

Views: 11265

Answers (4)

waliby
waliby

Reputation: 111

For anybody who would want to get the binary out of a temporary file, here is my solution:

<?php
   $temp = tmpfile();
   imagepng(imagecreatefromstring($imgBinary), $temp);
   $pathFile = stream_get_meta_data($temp)['uri']; // eg: /tmp/phpFx0513a
   $pngBin = file_get_contents($pathFile)
?>

Upvotes: 0

ElGato
ElGato

Reputation: 511

With php, you can convert any image to an other using imagepng, imagejpeg, imagegif :

imagepng(imagecreatefromstring(file_get_contents($input)), 'output.png');

In this example, it will save the uploaded image in png with the path 'output.png'

Upvotes: 3

BBonifield
BBonifield

Reputation: 5003

Personally, I prefer Image Magick over GD. It's a lot better if you're dealing with large images too; you can run into memory allocation issues with GD.

Upvotes: 3

Svisstack
Svisstack

Reputation: 16656

You can use PHP GD.

Upvotes: 0

Related Questions