Python image image resizing

I am trying to compress some jpeg images from 24X36 inches to 11X16.5 inches using the python image library. Since PIL deals with pixels, this should mean scaling from 7200X 4800 pixels to 3300 X2200 pixels with a resolution of up to 200 pixels / inch, however, when I run my PIL script, the resolution changes to 72 pixels / inch, and in the end I get more than 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 change image resolution when resizing images?

Thanks for any help!

+4
source share
1 answer

To save DPI, you need to specify it when saving; the info attribute is not always saved when processing images:

 dpi = im.info['dpi'] # Warning, throws KeyError if no DPI was set to begin with # resize, etc. out.save("out.jpg", dpi=dpi) 
+6
source

Source: https://habr.com/ru/post/1436457/


All Articles