Jan 26 2016 0

Compressing images using TinyPNG

To compress PNG I used to make use of a Mac application named PNG Compressor, but since this is a Mac application it is not much of use when I am not at home using my Mac. A quick search brought me to TinyPNG. Using their website you can upload your images to have them compressed. As soon as the compression is down you can download the images. Using TinyPNG

Using the Save to Dropbox’ button you can easily save all the compressed files directly into a Dropbox-folder of your choosing. Although it is named TinyPNG it compresses both PNG and JPEG images.

There is also an easy to use API (requires an API key) allowing you to incorporate their service into your own workflow. They even have a TinyPNG Photoshop plugin.

curl --user api:$YOUR_API_KEY \
     --data-binary @unoptimized.png -i https://api.tinify.com/shrink

If required there are several official client libraries available (Ruby, PHP, Node.js, Python and Java). Using the API key you will be able to compress 500 images per month fo free. For me 500 images per month should be more than enough.

Images uploaded with API Price per image
First 500 images per month free
Next 9 500 images per month $0.009 per image
Over 10 000 images per month $0.002 per image

Using the API via HTTPS/cURL

When using the API you will have to make two request

  1. Upload your image to compress it
  2. Download the compressed image

The first request will give you a response containing a location field. This indicates from where you can download the compressed image

The request to upload and compress you image (from the current directory)

curl https://api.tinify.com/shrink \
     --user api:YOUR_API_KEY \
     --dump-header /dev/stdout \
     --data-binary @unoptimized.jpg

and its the response

HTTP/1.1 201 Created
Compression-Count: 1
Location: https://api.tinify.com/output/2xnsp7jn34e5.jpg
Content-Type: application/json; charset=utf-8

{
  "input": {
    "size": 207565,
    "type": "image/jpeg"
  }
}

and to download the image

curl https://api.tinify.com/output/2xnsp7jn34e5.jpg \
     --user api:YOUR_API_KEY \
     --dump-header /dev/stdout --silent \
     --output optimized.jpg

giving you the following response

HTTP/1.1 200 OK
Compression-Count: 1
Image-Width: 530
Image-Height: 300
Content-Type: image/jpeg
Content-Length: 46480

[binary]

Workflow for the Workflow app

I was hoping to incorporate this into a workflow for the Workflow app, but I haven’t found a way to make the necessary calls to the TinyPNG API.

I found a thread on Reddit titled Interact with APIs via CURL or something similiar’ from approx. 10 months ago on which the Workflow Team responded with

Not yet, but definitely something we’d like to work on :)

So I guess I am not going to hold my breath for this feature to be available anytime soon.


Previous post
Bitcoin Instant - updated Feb 2, 2016 Jan 29, 2016: No earnings are being generated. Feb 1, 2016: Earnings are being generated again (something about a server move). No word on
Next post
Fixing dead links the proper way In my post ‘Fixing dead links’ I described a little piece of jQuery code to automatically redirect URLs from the old blog to the URLs used on
This blog is powered by Blot