Resize your Images

Online Image Resize, for PNGs, JPGs, GIFs and BMPs. 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.

Curl

# Resizing a JPG file (e.g. filename.jpg -> resized.jpg)
curl -X POST -s --form "op=fixedWidth&fixedWidth=200&input=@filename.jpg;type=image/jpg" http://img-resize.com/resize > resized.jpg

Node.js

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

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

// open the output file
var outStream = fs.createWriteStream('resized.jpg');

// do the request
var req = superagent
    .post('http://img-resize.com/resize')
    .attach('input', 'filename.jpg')
;

// save the returned file
req.end(function(res) {
    res.pipe(outStream);
});

PHP

Many thanks to Arjan Haverkamp for this example.

function ImgResize($JPGfile, &$error = '')
{
   $ch = curl_init('http://img-resize.com/resize');
   curl_setopt($ch, CURLOPT_TIMEOUT, 10);
   curl_setopt($ch, CURLOPT_FAILONERROR, 1);
   curl_setopt($ch, CURLOPT_POST, 1);
   curl_setopt($ch, CURLOPT_POSTFIELDS, array('input' => '@'.$JPGfile));
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   $jpg = curl_exec($ch);
   $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
   if ($status !== 200) {
      $error = 'img-resize.com request failed: HTTP code ' . $status;
      return false;
   }
   $curl_error = curl_error($ch);
   if (!empty($curl_error)) {
      $error = 'img-resize.com request failed: CURL error ' . $curl_error;
      return false;
   }
   curl_close($ch);
   return $jpg;
}

$result = ImgResize('input.jpg', $error);
if (false === $result) { die("{$error}\n"); }
file_put_contents('crushed.jpg', $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 or @andychilton.

(Ends)