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

How can I target output to a dynamic subdirectory? #43

Open
winston0410 opened this issue Aug 5, 2020 · 4 comments
Open

How can I target output to a dynamic subdirectory? #43

winston0410 opened this issue Aug 5, 2020 · 4 comments
Labels

Comments

@winston0410
Copy link

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

You should be able to use macros for that.

@winston0410
Copy link
Author

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 "
└──────┴──────────────┴──────┴─────┘

@vseventer
Copy link
Owner

@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.

@beevk
Copy link

beevk commented May 21, 2021

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants