Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lossless & output format #217

Closed
vivadavid opened this issue Jul 25, 2023 · 8 comments
Closed

Lossless & output format #217

vivadavid opened this issue Jul 25, 2023 · 8 comments

Comments

@vivadavid
Copy link

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

  • Caesium Image Compressor 2.4.1.

Operating System information

  • OS: Windows 11 22H2.

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
Copy link
Owner

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
Copy link
Owner

Lymphatus commented Jul 25, 2023

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 MediaInfo on Windows.

@vivadavid
Copy link
Author

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
Copy link
Owner

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

  • Converts the image to the new format using the maximum quality possible (100). Note that this can still mean that you can lose quality, regardless of the compression option selected. Think of a PNG with transparent background converted to JPG, the transparent pixels will be black.
  • If lossless is not selected, it will compress to the desired quality
  • If lossless is selected, it will just try to shave some size applying a lossless compression

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

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

@vivadavid
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants