我正在使用Python枕头来修改图像。每当我保存jpeg时,内部分辨率都将设置为72dpi。我正在寻找如何将其设置为其他值。我意识到这只是一个数字,并且在许多方面都毫无意义。我的动机是当我将图像读入Photoshop时使后续工作更容易。
最佳答案
我认为您可能正在寻找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))
这两个图像包含相同的像素,并且在磁盘上具有相同的大小,但是被编码为不同的图像大小和分辨率。许多图像查看器会以相同的方式显示它们,但是像GiMP和Photoshop这样的高端软件可以检测出差异。