在PHP中将JPG / GIF图像转换为PNG? [英] Convert JPG/GIF image to PNG in PHP?
本文介绍了在PHP中将JPG / GIF图像转换为PNG?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个允许图片上传和检查的PHP表单 exif_imagetype( );
确保图像有效。
I have a PHP form that allows image uploads and checks exif_imagetype();
to make sure an image is valid.
但是,我想要所有格式,PNG,JPG,JPEG和GIF结束一旦提交就成为PNG。
However, I want all formats, PNG, JPG, JPEG, and GIF, to end up being PNG once submitted.
我该如何做到这一点?
推荐答案
您只需要 imagepng()
。实际上它几乎变成了单行:
You just need imagepng()
then. In fact it almost becomes a one-liner:
imagepng(imagecreatefromstring(file_get_contents($filename)), "output.png");
您将使用 $ _ FILES [id] [tmp_name]
表示文件名,显然有不同的输出文件名。但探测图像格式本身会变得多余。
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.
这篇关于在PHP中将JPG / GIF图像转换为PNG?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文