vseventer / sharp-cli

CLI for sharp.
MIT License
189 stars 20 forks source link

document how to optimize a whole tree #26

Closed oupala closed 4 years ago

oupala commented 5 years ago

It appears that sharp-cli is embedding url-template that allow to use pattern matching in its command line.

It would be great to document that in the README file so that one can discover how to optimize a whole tree hierarchy.

Imagine there is the following tree:

directory/
directory/subdir1
directory/subdir1/image1.jpg
directory/subdir2
directory/subdir2/image2.png

I want to use a command that looks like npx sharp-cli resize 800 800 --format input --fit inside --input ./directory/**/*.{jpg|png} --output ./directory/ so that all jpg and png images are optimized and resized (if too big).

I found that url-template documentation is much too light and does not give much information about available variables.

@vseventer proposed something like --output "{dir}/{base}" but I could not succeed to make it work.

vseventer commented 5 years ago

I'm turning this into a bug ticket. The dependency used for output format parsing, url-template, is not designed for path parsing. I need to figure out a different solution.

oupala commented 4 years ago

Thanks for adding this feature so fast!

Unfortunately, I did not manage to make it work:

$ npx sharp-cli resize 800 800 --withoutEnlargement true --optimise true --progressive true --withMetadata false --format input --fit inside --input './docs/images/*/.jpg' --output {dir}/{base} info sharp Using cached /home/user/.npm/_libvips/libvips-8.8.1-linux-x64.tar.gz ENOENT: no such file or directory, open '/home/user/path/to/website//home/user/path/to/website/docs/images/photos/chambre_balcon.jpg'

Specify --help for available options

As you can see, there seems to be a problem in the path mentionned in the error: the absolute path is considered as a relative one.

It looks like {dir} is added twice.

vseventer commented 4 years ago

My bad - should be fixed now.

oupala commented 4 years ago

It appears to work well.

I still have another problem, but this might require a new issue.

I also want sharp-cli to optimize images that are in a hidden directory.

With bash, I can set how bash behave with setting a specific shopt option:

$ shopt -u dotglob
$ ls docs/**/*.jpg
$
$ shopt -s dotglob
$ ls docs/**/*.jpg
docs/.hidden/image.jpg
$

Is there a way to set a similar option for sharp-cli? If not, could it be possible to add options to set how sharp-cli behave?

$ npx sharp-cli --include-hidden-files
$ npx sharp-cli --include-hidden-directory