python降低图片分辨率_调整大小时的Python图像库图像分辨率

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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值