All of these examples should be immediately runnable in your language of choice. If you don't see your language feel free to contribute an example.


# Crushing a PNG file (e.g. filename.png -> crushed.png)
curl -X POST -s --form "input=@filename.png;type=image/png" https://pngcrush.com/crush > 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('https://pngcrush.com/crush');
   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 = "pngcrush.com request failed: HTTP code {$status}";
      return false;
   $curl_error = curl_error($ch);
   if (!empty($curl_error)) {
      $error = "pngcrush.com 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.