How to Change the DPI of an image using the PIL without saving? How to Change the DPI of an image using the PIL without saving? python-3.x python-3.x

How to Change the DPI of an image using the PIL without saving?


The PNG format stores DPI information in a metadata chunk in the file, it's called a "pHYs" chunk. So, you're really looking for a tool which can edit or add these kinds of chunks in/to PNG files without reading the image data itself.

A library which can do that is libpng and there exist Python bindings for it.

You might also want to check out this question which addresses the same problem. Apparently there are tools like IrfanView and ImageMagick which can change PNG files, like putting a pHYs metadata block in it.


Just posted an answer here: How to change the dpi or density when saving images using PIL, and I found this as well. I think the full answer posted on this will answer your question. In brief I would suggest to save a temp file and then delete it after you are done with it. I couldn't find any other workaround.