Convert JPG/GIF image to PNG in PHP?(在 PHP 中将 JPG/GIF 图像转换为 PNG?)
问题描述
可能重复
将jpg图像转换为gif、png &使用PHP的bmp格式
我有一个 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 PHP 中将 JPG/GIF 图像转换为 PNG?
基础教程推荐
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何替换eregi() 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
