Replies: 2 comments 6 replies
-
I wouldn't go so far as to say that you can "save essentially the original compressed image.jpg". It depends on what you mean by "essentially", but I don't think there is any guarantee that it will be the same as the original. See https://www.quora.com/Can-you-edit-and-re-save-a-JPEG-file-without-losing-quality Here is how "keep" is documented - https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#jpeg-saving
Is your goal to be able to save a JPEG2000 image without "losing quality" aka "modifying the pixels"? I think Pillow should already do that, provided that you haven't set |
Beta Was this translation helpful? Give feedback.
-
when doing Image.open('debug.jp2').save('debug-out.jp2') the output file is > 16 times larger. I might be wrong here, but I have always assumed that with JPEG files, at least, the original encoded data from the file is somehow kept around after Image.open() and so as soon as quality='keep' is used during save() it is that original encoded data that is actually written out. In other words, one may change the metadata of the file between open() and save() and still write the original encoded DCT harmonics out. And that's why the new size with JPEG is very close to the old one. And so I thought that it is just a matter of keeping that original encoded pixel data around with JPEG2000 as well in order to achieve the same effect. So, am I missing something? UPD. This actually suggests a way to make my original question a bit more concrete: suppose, I want to write code that loads a JPEG2000 file, changes EXIF metadata only and writes the file with updated metadata out. Obviously, I want to keep all pixel-related data as intact as possible when doing so. Is this doable with PIL? |
Beta Was this translation helpful? Give feedback.
-
Hi!
In my project, I am actively using the feature of PIL whereby calling
Image.open('image.jpg')
opens the JPEG file in a 'lazy' mode, which allows me to access image data on demand while leaving a chance to save essentially the original compressed image.jpg by callingImage.save('image.jpg', quality='keep')
. It comes handy in situations where one part of my code sends an Image.Image object to another part of the code, without needing to duplicate the original file object just in case a need to save the original arises.So, my question is: could you add this quality='keep' functionality to Image.save() for saving to JPEG2000 as well?
Beta Was this translation helpful? Give feedback.
All reactions