Content editors on my team need to add images to the web often, and each image needs to be optimized. I’ve decided I want to build them a Shortcuts app that can resize and compress multiple images in one easy swoop.
Google’s Squoosh app can seemingly do this using their npx command. After uploading an image in their interface, you can adjust the resizing and compression options in the right panel. Then, Squoosh will generate the npx command with those options configured.
The command generated with these options comes out to this:
npx @squoosh/cli --resize '{"enabled":true,"width":1280,"height”:auto,”method":"lanczos3","fitMethod":"stretch","premultiply":true,"linearRGB":true}' --mozjpeg '{"quality":75,"baseline":false,"arithmetic":false,"progressive":true,"optimize_coding":true,"smoothing":0,"color_space":3,"quant_table":3,"trellis_multipass":false,"trellis_opt_zero":false,"trellis_opt_table":false,"trellis_loops":1,"auto_subsample":true,"chroma_subsample":2,"separate_chroma_quality":false,"chroma_quality":75}'
To my knowledge, if I want to translate this operation into Shortcuts I would need a file input from the user, then run a shell script using that file input. So it looks like this:
However, I keep getting errors with every configuration I use. I can’t tell if I’m missing a step, my syntax is wrong, or there’s an error with the npx package.
Anyone have ideas for getting this to work?