tpet / mat2

mat2 is a metadata removal tool, supporting a wide range of commonly used file formats, written in python3: at its core, it's a library, used by an eponymous command-line interface, and a nautilus extension.
GNU Lesser General Public License v3.0
18 stars 5 forks source link

Why does image size get drastically reduced after using mat2? #5

Open fuzzah opened 2 months ago

fuzzah commented 2 months ago

Hello!

Why do my 20 Mb JPEGs turn into 5 Mb JPEGs after using mat2 on them? Does metadata really occupy 75% of total image size? Or maybe mat2 somehow reduces the image quality?

P.S. Can't find anything on the internet on this topic, all I get is tutorials on removing metadata :(

Baa14453 commented 2 months ago

Mat2 removes metadata from images by running them through pixbuf.savev, which opens and saves the image without any metadata. As a consequence, it compresses the image, mat2 doesn't specify the compression level: https://github.com/tpet/mat2/blob/21a244d6c6fcfbd9e3feb33a348678026d5824b8/libmat2/images.py#L114

This will always be the most reliable method of removing metadata, because only the picture data itself is transferred.

by default pixbuf sets a quality level of 75 for JPEGs: https://github.com/GNOME/gdk-pixbuf/blob/5a5d37bd6696c96d5567c2199cac0fbc5b86d0e8/gdk-pixbuf/io-gdip-jpeg.c#L39

which can sometimes be noticeable, particularly in dark areas e.g.: Original: mpv-shot0001

Cleaned: mpv-shot0001 cleaned

You can avoid compressing the image by using the Lightweight switch -L or --lightweight. This has a chance to leave some metadata but is better at preserving quality, the image size will mostly remain the same:

Lightweight: mpv-shot0001 cleaned

fuzzah commented 2 months ago

@Baa14453 thank you! So changes need to be made to mat2 in order for it to specify 100% quality or something like that?