Lymphatus / caesium-image-compressor

Caesium is an image compression software that helps you store, send and share digital pictures, supporting JPG, PNG, WebP and TIFF formats. You can quickly reduce the file size (and resolution, if you want) by preserving the overall quality of the image.
https://saerasoft.com/caesium
GNU General Public License v3.0
3.47k stars 209 forks source link

Lossless & output format #217

Closed vivadavid closed 1 year ago

vivadavid commented 1 year ago

Describe the bug If I add a PNG file, select Lossless and set Output to JPG, the file produced by Caesium has a JPG extension, but it's actually a PNG file as shown by MediaInfo or ExifTool.

Software version

Operating System information

To Reproduce

  1. I add a PNG file.
  2. I select Lossless.
  3. I set Output to JPG.

Expected behavior As Output is set to JPG, I expect to obtain a JPEG image. For my purposes, I need to get a JPEG file, but I also need, in some circunstances, to get the best quality as possible, and that's why I mark Lossless. If there's some kind of contradiction between choosing lossless and converting from PNG to JPEG, maybe Caesium should display some info. In any case, the converted file should have the extension that corresponds to the format it's using.

Application Log caesium-2023-07-25.log

Lymphatus commented 1 year ago

If there's some kind of contradiction between choosing lossless and converting from PNG to JPEG

There is. The two options don't really make sense together, since converting can result in a loss of quality. The example you provided, from PNG to JPG is one of them. I should probably print a warning for this kind of combination, but still the output should always be in the desired format (JPG in your example). I'll take a look into it.

Lymphatus commented 1 year ago

By the way I just tested your scenario and the output from a PNG is a JPG. I checked the file with file on Linux and MediaInfoon Windows.

vivadavid commented 1 year ago

If turning on Lossless on a PNG implies keeping the format, while I need to convert my image to JPEG, I guess the only thing I could is trying different quality percentages.

Would the opposite make thense? A scenario where I have a JPEG file, I turn on Lossless and I set Output to PNG.

Lymphatus commented 1 year ago

If you select an output format different from the original the app does something like this:

Converting a JPG to a PNG will preserve the image as is, even though it will probably increase in size. The opposite is not true, because JPG is lossy by default and just the PNG -> JPG process will degrade the image, even so slightly.

Hope is more clear, feel free to ask anything else if you still have doubts.

vivadavid commented 1 year ago

Hi, @Lymphatus ,

Thank you for the explanation.

Despite not making much sense and despite the loss of quality, I think it'd still be nice if Caesium could apply lossless to a PNG image that could be converted to a JPEG. I'm thinking about a context where you absolutely need a JPEG as output but, at the same time, you want to get the best possible quality within some limits.

Lymphatus commented 1 year ago

For the PNG -> JPG Caesium already performs a conversion with 100 quality applied and then goes for lossless optimization. Since the quality difference in the range 80-100 is usually very minimal, going for lossless after a conversion - in my personal opinion - will just give you a bigger image without any real gain in quality. It's counterintuitive, but converting PNG -> JPG with quality 80-90 can achieve very similar result as lossless with much much smaller image.

You can do some tests and see by yourself what's the best tradeoff for you.

vivadavid commented 1 year ago

In that case, I'll do that. Thanks, @Lymphatus !

vivadavid commented 1 year ago

Hi,

Sorry that I've reopened the thread, but I wanted to test the issue on 2.5.0.

Despite not being recommended, I've tried to convert a PNG file with Lossless on, Skip if output size is bigger than original on and Output set to JPG. The results seem contradictory:

  1. I get a message saying Compression finished.
  2. On the Info field, I get a message saying Skipped: compressed file is bigger than the original.
  3. In file explorer, there's actually a new JPEG file, so the conversion was completed.
  4. The JPEG file is still a PNG, as shown by Mediainfo or ExifTool.
  5. The converted file has the same date as the original despite Keep file dates being off. Edited: I've just hashed both files and they are exactly the same, except for the wrong extension of the converted image.

caesium-2023-08-08.log