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

When you remove JPEG metadata, the quality of the images changes #3

Open
Shyryp opened this issue Dec 28, 2024 · 1 comment
Open

When you remove JPEG metadata, the quality of the images changes #3

Shyryp opened this issue Dec 28, 2024 · 1 comment

Comments

@Shyryp
Copy link

Shyryp commented Dec 28, 2024

When you remove JPEG metadata, the quality and size of the image change

The thing is that your code does not take into account that Pillow saves files with default quality settings.
You need to take this into account in your code, because otherwise JPEG images lose quality, and if they were previously compressed, they increase in size (since they acquire the default quality that Pillow sets).

You need to do something with the "quality" and "subsampling" parameters at the .save() stage.

However, I do not yet understand how to fix this, since the original JPEG files do not have metadata about quality and subsampling, and the "keep" value does not work because Pillow sets format = None when creating a new image, which leads to an error.

If you set the values ​​"quality" = 100 and "subsampling" = 0, then the created images will weigh almost as much as PNG images, although compression methods that reduce their weight could have been applied to the original JPEG images earlier.

if original_format == "JPEG":
    save_params["quality"] = 100
    save_params["subsampling"] = 0

img_no_metadata.save(file_path, format=original_format, **save_params)

This problem needs to be solved, because otherwise the library spoils the quality and volume of the original JPEG files (and possibly other formats).

@Shyryp
Copy link
Author

Shyryp commented Dec 28, 2024

Confirmation from the author of another library that JPEG images are recoded when using the Pillow library:
sh1d0wg1m3r/Metadata-Removal-Tool#2

You also need to do something so that users of your library do not lose image quality and size when resaving with the removal of metadata.

Good luck with solving the problem!

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

No branches or pull requests

1 participant