【发布时间】:2011-03-12 20:25:04
【问题描述】:
我想将输入的 24 位 PNG 图像转换为 8 位,我尝试过使用 Imagemagick 和 Python PIL,都不起作用。
例如:
在 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 输出 24->8 个 png 转换(我需要) alt text http://img695.imageshack.us/img695/934/psout.png
通过我的 Python 函数转换
alt text http://img638.imageshack.us/img638/6762/pythonout.png
【问题讨论】:
-
“甚至不触摸图像”到底是什么意思?
png8image.png根本没有被创建吗? -
创建但没有区别(只是同一个副本,但有另一个名字)
-
您好,我想将输入的 24 位 PNG 图像转换为 8 位,我已经通过 Imagemagick 和 Python PIL 尝试过,但都不起作用。 应该是 我想将输入的 24 位 PNG 图像转换为 8 位。我曾尝试使用 Imagemagick 和 Python PIL,但都不起作用。
-
您想从 24 位转到 8 位吗?在这种情况下,请适当地编辑问题标题。
-
哦,谢谢你指出 Thomas,已修复 :)
标签: python image png imagemagick