Giter VIP home page Giter VIP logo

Comments (13)

oupala avatar oupala commented on June 19, 2024

I was looking for something like this imagemagick command:

convert -resize 640x640> *.jpg "${pattern}-%d.jpg"

from sharp-cli.

vseventer avatar vseventer commented on June 19, 2024

Try using the --fit inside option - see https://sharp.pixelplumbing.com/en/stable/api-resize/#resize

from sharp-cli.

oupala avatar oupala commented on June 19, 2024

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.

vseventer avatar vseventer commented on June 19, 2024

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.

oupala avatar oupala commented on June 19, 2024

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.

vseventer avatar vseventer commented on June 19, 2024

Yes, you can use this right from the CLI - see my last reply for an example.

from sharp-cli.

oupala avatar oupala commented on June 19, 2024

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.

vseventer avatar vseventer commented on June 19, 2024

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.

oupala avatar oupala commented on June 19, 2024

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.

vseventer avatar vseventer commented on June 19, 2024

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.

oupala avatar oupala commented on June 19, 2024

I understand the limitation that you encountered.

But I would be very happy to see this feature back in sharp.

from sharp-cli.

vseventer avatar vseventer commented on June 19, 2024

I created this request in #24. Closing this.

from sharp-cli.

mathieu-aubin avatar mathieu-aubin commented on June 19, 2024

you could pipe output to 'sponge' and save as same file. Otherwise, input file gets destroyed before reading

from sharp-cli.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.