开发者

PHP Image Convert

In my web app users are allowed to upload images as their phot开发者_运维问答os. How can I convert different image extensions to JPG? Input files are JPG, PNG or GIF.


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.


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'


You can use PHP GD.


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)
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜