Compress images via TinyPNG/JPEG?

Hi,

I’m trying to auto-compress images via http://tinypng.com/, via their API; https://tinypng.com/developers/reference

(One can get the API key here, takes ±20 seconds; https://tinypng.com/developers)

I’ve been successfull sending the CURL request via;

// @$KMVAR_Path takes the current selected file
curl -i --user api:{API_KEY} --data-binary @$KMVAR_Path https://api.tinify.com/shrink

But not successfull with actually downloading the image.
When executing the above I get the json response similar to;

{"input":{"size":299538,"type":"image/jpeg"},"output":{"size":45240,"type":"image/jpeg","width":1000,"height":667,"ratio":0.151,"url":"https://api.tinify.com/output/imgname.jpg"}}

Tried saving the response and continue from there, but that seems to be a big mess.

PS. Retreiving a image can be done via;

curl --dump-header /dev/stdout --silent api:{API_KEY} --output test.png https://api.tinify.com/output/imgname.jpg

Any thoughts?

Thanks!
Jeroen

Why don’t you use a command line utility which resides on your machine locally? Maybe Imageoptim-CLI?

TinyPNG is by far the best optimization I’ve tested. I’ve done extensive testing in the past and they came out best in regards of compressing and rarely quality loss. So that why I really like them.

Besides that I prefer to not be reliant on installing command line utility.

Hi Sormano,

Did you manage to create this macro? I am currently trying to use TinyPNG API with Keyboard Maestro.

TIA


Cary

Hi Cary,

Unfortunately not. As it wasn’t too important for me I didn’t spend hours trying to though…

Cheers,
Jeroen

Hello,

Ok, I managed to create a macro:

Compress with TinyPNG.kmmacros (51.8 KB)

This macro will take a set of PNG or JPG files and compress them using the online TinyPNG service: https://tinypng.com/

You need an active internet connection and an API key for this to work.

Grab your unique API key here: https://tinypng.com/developers (the free one allows you to convert up to 500 PNG files per month) and enter it here:

The process may take some time, especially if you have selected several large image files, but you will be notified on completion.

Spot the difference:


Cary

Hi Cary

7 years later, and I found your macro and installed it and it works perfectly! I have been a regular user of TinyPNG for website work and it just made so much sense to automate the process with KBM.

It works for a Finder selection. But I have recently been using alternative Finder apps such as Forklift and Pathfinder. So the "Finder's Selection Collection" for the Execute Action does not work with these. Nor does the option to use "Running Application's Collection".

I will start investigating further, but perhaps someone has already encountered this issue and may have a solution at hand?

Thanks again.

John

1 Like

It's always good to jump in the deep end and give it a go yourself.
After a bit of experimentation, here is the change I finally ended up making, so that this works now in Forklift...

Hi John,

For Path Finder, please see this thread: