问题描述
im使用以下脚本将jpgs转换为灰度图像. http://bubble.ro/How_to_convert_an_image_to_grayscale_using_PHP.html
im using the following script to convert jpgs into grayscale-images.http://bubble.ro/How_to_convert_an_image_to_grayscale_using_PHP.html
我想对其进行升级,以将png(具有透明性)和gif(具有透明性)也转换为灰度图像.
i want to upgrade it to also convert pngs (with transparency) and gifs (with transparency) into grayscale images.
目前无法正常工作.我正在查询image-src的文件扩展名.如果是jpg,if,gif或png,我会调用适当的imagecreatefrom-jpg-gif-png
At the moment it's not working. I'm querying the image-src for its file-extension. If jpg, if, gif, or if png i call the appropriate imagecreatefrom-jpg-gif-png
但是,我一直在运行相同的for循环,但是gif只能得到灰色矩形,每个像素都是灰色. Png几乎可以正常工作,但是png中的透明度变成了黑色.
However i'm always running the same for-loop and gifs unfortunately only get gray rectangles, every pixel is gray. Png's almost work, however transprency in pngs gets transformed to black.
有什么想法吗?
推荐答案
$image = ImageCreateFromString(file_get_contents('/path/to/image.ext'));
ImageFilter($image, IMG_FILTER_GRAYSCALE);
ImageGIF($image); // or ImagePNG($image);
这篇关于PHP:将png和gif转换为灰度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!