resurrecting-open-source-projects / scrot

SCReenshOT - command line screen capture utility
Other
511 stars 51 forks source link

quality wrong at man page #277

Closed Disonantemus closed 1 year ago

Disonantemus commented 1 year ago

man scrot.1

       -q, --quality NUM
              NUM must be between 1 and 100. For lossless output formats, a higher value represents better
              but  slower  compression. For lossy output formats, a higher value represents higher quality
              and larger file size. Default: 75.

It's inverse of that for lossless, saving a lossless format like default png:

> time scrot --quality 1; time scrot --quality 100

quality size speed
1 314kb 397ms
100 5.94MB 107ms

Also, using '--format webp' it's better than pngto get smaller lossless screenshots, only --quality 100 appears lossless to me (webp has lossless and lossy compression) you can test with 'cwebp' (libwebp), and ti would be better to have that quality control, maybe a '--losslessoption; with same file tested before: cwebp in.png -o out.webp -z 9`

format size
webp -z 9 136kb
optipng -o7 254kb
N-R-K commented 1 year ago

Confirmed.

However, it's hard to tell how this is supposed to work because imlib2's "quality" thing is entirely undocumented (as far as I can see). So I'm not even sure what that manpage description is based on.

Looks like it got introduced at https://github.com/resurrecting-open-source-projects/scrot/commit/fc27d9f7301df1c7577be9080da7fc14e9c5836e. Before that commit it used to say:

  -q, --quality NUM  Image  quality (1-100) high value means high size, low
                     compression. Default: 75. (Effect differs depending on
                     file format chosen).

Which was correct for PNG files, but probably not correct for other files.

Note to self: open an issue at imlib2 asking for documentation/clarification on how the "quality" value is supposed to work.

N-R-K commented 1 year ago

Also, using '--format webp' it's better than pngto get smaller lossless screenshots, only --quality 100 appears lossless to me (webp has lossless and lossy compression) you can test with 'cwebp' (libwebp), and ti would be better to have that quality control, maybe a --lossless option; with same file tested before: cwebp in.png -o out.webp -z 9

There's plan to add a separate --compression flag, see #290. So once that's implemented, you should be able to do something like scrot --format webp --quality 100 --compression 9 to get highly compressed lossless webp (or jxl with new imlib2 version).

But until that's implemented, you can use the following, which will run the cwebp command on the new screenshot:

$ scrot -e 'cwebp $f -o $f -z 9 -lossless'
Disonantemus commented 1 year ago
-e 'cwebp $f -o $f -z 9 -lossless'

If I do that ...\ I get webp file but with .png extention:

> scrot -e 'cwebp $f -o $f -z 9 -lossless'
2023-05-08-094948_1920x1080_scrot.png

If I try to "force" an extention, I get 2 files, $n didn't work, just output same as $f, maybe it's expected, but I did try, like this:

> scrot  -e 'cwebp $f -o $n.webp -z 9 -lossless'
2023-05-08-094948_1920x1080_scrot.png
2023-05-08-094948_1920x1080_scrot.png.webp

Same as before, but I can remove old one:

> scrot  -e 'cwebp $f -o $n.webp -z 9 -lossless; rm $f'
2023-05-08-094948_1920x1080_scrot.png.webp

Now, how can I get a file with no '.png' in the name? I did try with '${f%.*}' (some shell expansion with no success).

N-R-K commented 1 year ago

Now, how can I get a file with no '.png' in the name? I did try with '${f%.*}' (some shell expansion with no success).

You can give scrot a filename: scrot -e 'cwebp $f -o $f -z 9 -lossless' shot.webp. See the "SPECIAL STRINGS" section of the manpage also if you want the filename to have date/time etc.

Disonantemus commented 1 year ago

Thanks! that worked!

I did read that part, because I did use "$n" (basename), but didn't work as a parameter for cwebp, but with your example I can customize it to my liking.

N-R-K commented 1 year ago

only --quality 100 appears lossless

BTW, imlib2 currently doesn't support lossless webp encoding. I submitted a patch to fix it which was merged into the current git master. So in the next imlib2 update, you should be able to get lossless encoding with -q 100.