tjko / jpegoptim

jpegoptim - utility to optimize/compress JPEG files
http://www.iki.fi/tjko/projects.html
GNU General Public License v3.0
1.56k stars 116 forks source link

Pass stdin to stdout if optimization was not possible #50

Closed KrylosovM closed 2 years ago

KrylosovM commented 7 years ago
cat a.jpg | jpegoptim --stdin > b.jpg

Would be great if input file from stdin passed to stdout when result of optimization is larger than original. At the moment --stdin option enables --force option that forces optimized file to stdout, even if it is larger than original.

Lewiscowles1986 commented 6 years ago

I Just got this same thing trying to make this into a serverless function.

https://github.com/Lewiscowles1986/func_jpegoptim

Lewiscowles1986 commented 6 years ago

going to try this out with a build.

Lewiscowles1986 commented 6 years ago

Right I've a patch for this. It was a bit more of a pain than I first thought, but it now works on my PC and I'm pretty happy

Lewiscowles1986 commented 6 years ago

@KrylosovM @tjko My solution would likely benefit from feedback. I've made a heap of assumptions, but I feel pretty positive about it.

The latest commit adds a command line argument for --read-bytes shortcode -B which takes the number of bytes passed to stdin. It also checks that is larger than the minimum possible size for a valid JPEG, and detects if the input to stdin is larger than the buffer (defaults to 32MB).

It does change the behaviour so that -f is not passed by default and that output is silenced when --stdin or --stdout arguments are provided.

tjko commented 2 years ago

This has now been implemented with commit: 05c3f85aa1330f88f20b86c9d535a72735ed33a1