使用 PHP 将 jpg 图像转换为 gif、png 和 bmp 格式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/755781/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 23:45:56  来源:igfitidea点击:

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

phpimage-processing

提问by riad

How can I convert a single jpg image into 3 different image format gif , png and bmp using PHP?

如何使用 PHP 将单个 jpg 图像转换为 3 种不同的图像格式 gif、png 和 bmp?

Pls help

请帮忙

回答by soulmerge

You first create an image object out of your file with imagecreatefromjpeg(). You then dump that object into different formats (using imagegif()for example):

您首先使用imagecreatefromjpeg()从文件中创建一个图像对象。然后将该对象转储为不同的格式(例如使用imagegif()):

$imageObject = imagecreatefromjpeg($imageFile);
imagegif($imageObject, $imageFile . '.gif');
imagepng($imageObject, $imageFile . '.png');
imagewbmp($imageObject, $imageFile . '.bmp');

回答by Jarrod

I've set up a new opensource project on Github that allows reading and saving of BMP files (actual BMP files, not wbmp), and other file formats, in PHP. It's nice and easy to use.

我在 Github 上建立了一个新的开源项目,允许在 PHP 中读取和保存 BMP 文件(实际的 BMP 文件,而不是 wbmp)和其他文件格式。它很好,易于使用。

The project is called PHP Image Magician.

该项目名为PHP Image Magician