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

Pass stdin to stdout if optimization was not possible #50

Closed
KrylosovM opened this issue Sep 12, 2017 · 5 comments
Closed

Pass stdin to stdout if optimization was not possible #50

KrylosovM opened this issue Sep 12, 2017 · 5 comments

Comments

@KrylosovM
Copy link

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

Lewiscowles1986 commented Oct 24, 2017

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

https://github.com/Lewiscowles1986/func_jpegoptim

@Lewiscowles1986
Copy link

going to try this out with a build.

Lewiscowles1986 added a commit to Lewiscowles1986/jpegoptim that referenced this issue Oct 25, 2017
See tjko#50

Fixes tjko#50

* Read `STDIN` into buffer `inbuf`
* Modified flags so that `--stdout` (enabled by using `--stdin`) also enforces quiet & lowers verbosity
* Added checks to compensate for `fclose` and `free` calls
* Added output logic in the case that input stream is smaller than optimized output stream

Signed-off-by: Lewis Cowles <lewiscowles@me.com>
@Lewiscowles1986
Copy link

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

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

tjko commented Apr 6, 2022

This has now been implemented with commit: 05c3f85

@tjko tjko closed this as completed Apr 6, 2022
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

Successfully merging a pull request may close this issue.

3 participants