Crush your PNGs

PNG Crush. Free! Provides an API. Simple Quick and Fast.

Digital Ocean

We recommend Digital Ocean for hosting your sites. Free $10 credit when you sign up.


# Crushing a PNG file (e.g. filename.png -> crushed.png)
curl -X POST -s --form "input=@filename.png;type=image/png" > crushed.png


// core
var fs = require('fs');

// from npm
var superagent = require('superagent');

// open the output file
var outStream = fs.createWriteStream('crushed.png');

// do the request
var req = superagent
    .attach('input', 'filename.png')

// save the returned file
req.end(function(res) {


Many thanks to Arjan Haverkamp for this example and Kevin Op den Kamp for an update.

function PNGcrush($PNGfile, &$error = '')
   $ch = curl_init('');
   curl_setopt($ch, CURLOPT_TIMEOUT, 10);
   curl_setopt($ch, CURLOPT_FAILONERROR, 1);
   curl_setopt($ch, CURLOPT_POST, 1);
   curl_setopt($ch, CURLOPT_POSTFIELDS, [
      'input' => new CurlFile($PNGfile, 'image/png', $PNGfile)
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

   $png = curl_exec($ch);
   $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
   if ($status !== 200) {
      $error = " request failed: HTTP code {$status}";
      return false;
   $curl_error = curl_error($ch);
   if (!empty($curl_error)) {
      $error = " request failed: CURL error ${$curl_error}";
      return false;
   return $png;

$result = PNGcrush('input.png', $error);
if (false === $result) { die("{$error}\n"); }
file_put_contents('crushed.png', $result);

More Languages

I'd love to add more examples in your favourite programming language, so feel free to send them my way. andychilton at that gmail place in the sky.