我想把输入的24位PNG图像转换成8位,我试过使用Imagemagick和Python,两者都不起作用。
例如:
在Imagemagick,我尝试将控制台命令转换为这样:
convert -depth 8 png24image.png png8image.png
下面是我尝试用python的方式:
import Image
def convert_8bit(src, dest):
"""
convert_8bit: String, String -> void.
Converts the input image file into 8bit depth.
"""
im = Image.open(src)
if not im.mode == "P":
im2 = im.convert("P", rgb2xyz)
im2.save(dest)
Imagemagick甚至不触及图像,而python函数则减少到8位,但保留唯一的编号164而不是256。当从24位png图像转换为png8时,Photoshop用于将图像转换为具有256唯一数字的8位。
谢谢
编辑:
通过Photoshop (我需要) alt文本http://img695.imageshack.us/img695/934/psout.png实现24->8 png转换的输出
通过我的Python函数转换的
发布于 2010-07-07 15:19:01
看起来,convert
方法上的量化方法没有做正确的事情。试试这个:
im2 = im.convert('RGB').convert('P', palette=Image.ADAPTIVE)
向RGB
的额外转换可能是多余的。我从http://nadiana.com/pil-tips-converting-png-gif那里得到了这个提示
发布于 2010-07-07 14:16:52
我这样做(在PHP中使用Imagick ):
$colors = min(255, $im->getImageColors());
$im->quantizeImage($colors, Imagick::COLORSPACE_RGB, 0, false, false );
$im->setImageDepth(8 /* bits */);
https://stackoverflow.com/questions/3195509
复制相似问题