sharp-cli
sharp-cli copied to clipboard
How can I target output to a dynamic subdirectory?
I have multiples subdirectories in my image directories, and I want to convert images inside these subdirectories and output the formatted files there.
I tried with the following cmd but it outputs all files in the main directory, images. Is something like this possible? Do I need to hard code subdirectories?
npx sharp --input './dist/images/**/*.jpg' --output './dist/images/' -f webp;
You should be able to use macros for that.
Thank you so much for you reply. I tried both methods, hardcoding paths and using macros. Hardcoding paths only works when you don't care about the subdirectories. Macros( {dir} )did respect subdirectories, but I cannot change their value. Is it possible to modify the value in {dir}, or is there any workaround to achieve the following?
Take the example from README:
Input path:
┌─────────────────────┬────────────┐
│ dir │ base │
├──────┬ ├──────┬─────┤
│ root │ │ name │ ext │
" / home/user/dir / file .txt "
└──────┴──────────────┴──────┴─────┘
Expected output path:
┌─────────────────────┬────────────┐
│ dir │ base │
├──────┬ ├──────┬─────┤
│ root │ │ name │ ext │
" / home/user/formatted-dir / file .txt "
└──────┴──────────────┴──────┴─────┘
@winston0410 I see what you want to achieve, and I don't think it's easily doable today. If you can point me to a library or pattern that could be used to implement something like this, let me know and I'll be happy to take a look.
@vseventer Maybe this will help: JPEG-Compressor-CLI
jpgc -r -o ./out/
This option (-o) generates all the files in ./out directory while also maintaining the original directory structure.