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!
If you want to resize an image without losing quality, you need to make sure that the "Resample" checkbox is unchecked. This checkbox tells Paint to change the number of pixels in the image. When you uncheck this box, Paint will not change the number of pixels, and the quality of the image will not be reduced.
Most of the time, reducing an image's size or dimensions won't affect the image's quality. Making an image to be larger than its original dimensions can be tricky. Resizing an image larger than its original dimensions can affect the quality.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With