用Python的pillow库设置图像分辨率

4

我正在使用Python Pillow修改图片。每当我保存jpeg格式的图片时,内部分辨率会被设置为72dpi。我想知道如何将其设置为不同的值。我意识到这只是一个数字,在很多方面都是无意义的。我的动机是在将图片读入Photoshop时,使后续工作更加容易。

2个回答

6

我想你可能在寻找dpi(每英寸点数)相关的内容。

from PIL import Image, ImageDraw

# Make a white background with a blue circle, just for demonstration
im = Image.new('RGB', (800, 600), (255, 255, 255))
draw = ImageDraw.Draw(im)
draw.ellipse((200, 100, 600, 500), (32, 32, 192))

# the default
im.save("image_72.jpeg")

# explicit dpi for high resolution uses like publishing
im.save("image_300.jpeg", dpi=(300, 300))

两幅图像包含相同的像素,并且在磁盘上的大小也相同,但它们被编码为不同的图像尺寸和分辨率。许多图像查看器会以相同的方式显示它们,但高端软件如The GiMP和Photoshop可以检测到差异。


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接