Comments (13)
I was looking for something like this imagemagick command:
convert -resize 640x640> *.jpg "${pattern}-%d.jpg"
from sharp-cli.
Try using the --fit inside
option - see https://sharp.pixelplumbing.com/en/stable/api-resize/#resize
from sharp-cli.
Thanks a lot, that was what I was looking for.
Is there a way to overwrite the input file, or to set a pattern for naming the out files (something like ${original_name}-resized.jpg)?
All what I saw on the README file is that sharp-cli is made for one file at a time (even if bash car use jokers to change multiple files at a time).
You can have an example of such pattern in the imagemagick command above.
And it seems that overwriting is explicitly forbidden by the cli. Here is an error of the cli when trying to overwrite an input file:
Cannot use same file for input and output
from sharp-cli.
You can use url-templates for this - for example sharp resize 800 600 --fit inside -i ./src/*.jpg -o ./dest/{name}{ext}
. Batch processing is supported.
from sharp-cli.
Is there a way to use sharp and url-templates directly in a CLI?
Or is it mandatory to create a js script to use both of them in cunjunction?
from sharp-cli.
Yes, you can use this right from the CLI - see my last reply for an example.
from sharp-cli.
You mean, I juste have to install url-templates globally, then to enter the following command:
sharp resize 800 600 --fit inside -i ./src/*.jpg -o ./dest/{name}{ext}
and {name}
and {ext}
will be automatically defined?
It is still not possible to overwrite the source file with this solution, right?
from sharp-cli.
Everything already comes with the CLI - just try and run the command in my example above. Overwriting the source file is not supported.
from sharp-cli.
You're right, I tested it and it works perfectly, impressive! Is this feature documented somewhere?
The only thing I am missing is overwriting. What a pity... I'll have to find a workaround.
from sharp-cli.
The CLI used to be able to do that, but I removed support for it since it led to problems with large files. Large files work great with streams, but we cannot use streams when saving to the same file.
I might be able to add a --overwrite
flag in the CLI, which when set would overwrite the input file. Gotcha would be that you should use this flag only for small files.
from sharp-cli.
I understand the limitation that you encountered.
But I would be very happy to see this feature back in sharp.
from sharp-cli.
I created this request in #24. Closing this.
from sharp-cli.
you could pipe output to 'sponge' and save as same file. Otherwise, input file gets destroyed before reading
from sharp-cli.
Related Issues (20)
- Resize by percentage HOT 2
- Remove people's data from the git history HOT 1
- Update `sharp` dependency to `v0.28` to support `AVIF` format
- Overwriting the input files failes in Node v16.4.1 HOT 1
- Does not Install on ARM64 M1 Apple Silicone HOT 2
- Specifying quality changes PNG file format to ISO Media HOT 4
- CPU usage low... HOT 3
- Option to delete original? HOT 3
- How to specify background/border color for `extend`? HOT 5
- Support for composite multiple images HOT 5
- NPM flags 3 moderate severity vulnerabilities upon install HOT 3
- Proposal: Add `--animated` Global Option HOT 2
- Add support PPM files HOT 7
- avif output ext wrong HOT 2
- Input file specification on windows - Backslash HOT 6
- Possible to add output option to buffer HOT 2
- sharp-cli vs sharp
- How to rasterize SVGs on PNG with specific width/height? HOT 4
- Greyscale conversion is not working HOT 6
- Installation does not work on Manjaro
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sharp-cli.