调整大小时的Python图像库图像分辨率 [英] Python Image Library Image Resolution when Resizing

查看:1625
本文介绍了调整大小时的Python图像库图像分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用python图像库将一些jpeg图像从24X36英寸缩小到11X16.5英寸。由于PIL处理像素,这应该意味着从7200X 4800像素缩放到3300 X2200像素,我的分辨率设置为200像素/英寸,但是当我运行我的脚本PIL时将分辨率更改为72像素/英寸,我最终得到更大比以前的图像。

 导入图片

im = Image.open(image.jpg )

if im.size ==(7200,4800):
out = im.resize((3300,2200),Image.ANTIALIAS)
elif im.size ==(4800,7200):
out = im.resize((2200,3300),Image.ANTIALIAS)

out.show()

当我调整图像大小时,有没有办法保持我的图像分辨率?



<感谢您的帮助!

解决方案

要保存DPI,您需要在保存时指定它; <$ p $ c> info 属性并不总是在图像处理中保留:

  dpi = im.info ['dpi'] #Warning,如果没有将DPI设置为以

#resize等开头,则抛出KeyError

out.save(out.jpg ,dpi = dpi)


I am trying to shrink some jpeg images from 24X36 inches to 11X16.5 inches using the python image library. Since PIL deals in pixels this should mean scaling from 7200X 4800 pixels to 3300 X2200 pixels, with my resolution set at 200 pixels/inch, however when I run my script PIL changes the resolution to 72 pixels/inch and I end up with a larger image than i had before.

import Image

im = Image.open("image.jpg")

if im.size == (7200, 4800):
    out = im.resize((3300,2200), Image.ANTIALIAS)
elif im.size == (4800,7200):
    out = im.resize((2200,3300), Image.ANTIALIAS)

out.show()

Is there a way to mantain my image resolution when I'm resizing my images?

thanks for any help!

解决方案

To preserve the DPI, you need to specify it when saving; the info attribute is not always preserved across image manipulations:

dpi = im.info['dpi']  # Warning, throws KeyError if no DPI was set to begin with

# resize, etc.

out.save("out.jpg", dpi=dpi)

这篇关于调整大小时的Python图像库图像分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆