shssoichiro / oxipng

Multithreaded PNG optimizer written in Rust
MIT License
2.95k stars 124 forks source link

Feature request: accept png paths list as stdin to ease wrapper script creation #629

Open montehurd opened 5 months ago

montehurd commented 5 months ago

If a png paths list could be passed via stdin it would be easier to optimize a subset of a collection of images ( in my use case this subset is unoptimized images ) while still leveraging oxipng's great built-in thread spawning to churn through them efficiently

ILoveGoulash commented 3 months ago

That's what xargs is for.

montehurd commented 3 months ago

@ILoveGoulash Not trying to make N calls to it. Trying to let it handle thread spawning

Unless I misunderstand what you are suggesting?

ILoveGoulash commented 3 months ago

Yes, printf '%s\n' *.png | tr '\n' '\0' | xargs -0 oxipng is (minus corner cases related to ARG_MAX) identical to oxipng *.png. xargs -n1 is what would make a single call per file.

But well, since oxipng does nothing with its stdin (I think?), it'd be cool to read it and add PNGs to the work queue asynchronously (something xargs can't do).

murlakatamenka commented 1 month ago

@montehurd just use fd:

# files will be processed 1 by 1 (i.e. not in parallel) and oxipng will be multithreaded
fd . --extension png --threads 1 --exec oxipng --preserve --opt max {}

# or with short flags
fd . -e png -j 1 -x oxipng -p -o max {}

# alternatively, run N threads for N files with single-threaded `oxipng`
fd . -e png -x oxipng -t 1 -p -o max {}