Try Tuts+ Premium, Get Cash Back!
Create Instagram Filters With PHP

Create Instagram Filters With PHP

Tutorial Details
  • Program: PHP / ImageMagick
  • Difficulty: Intermediate
  • Estimated Completion Time: 45 minutes

Final Product What You'll Be Creating

In this tutorial, I’ll demonstrate how to create vintage (just like Instagram does) photos with PHP and ImageMagick. Wait? What? Yes, you can do this very thing with PHP and ImageMagick, and that’s just scratching the surface!


We Made Digital Vintage Photos, Before it Was Cool

Once upon a time – technically 22 years ago (5 years before PHP) – ImageMagick was released. Since then, it has evolved to a platform independent software suite that can create, edit, compose, or convert raster images (over 100 formats supported!). You can use it to resize, flip, mirror, rotate, distort, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves. It truly has everything you will ever need, when dealing with image manipulation in web development, video processing, panorama generating, etc. Please note, however: it is not a GUI image editor.

ImageMagick is command-line Photoshop for web.


Image Manipulation With PHP

PHP comes bundled with GD (GIF Draw/Graphics Draw), which is a library for the dynamic creation of images. It can be used for simpler image operation, such as resizing, cropping, adding watermarks, creating thumbnails (Jeffrey wrote about it), applying basic photo filters – you’ve probably used it before. Unfortunately, if you want to create something more complex with GD, like Instagram effects, you can’t. Luckily, though, we have ImageMagick!


GD vs. ImageMagick

These two can’t compare on higher levels, therefore, we will use simple example, like resizing. Let’s imagine that we’ve uploaded a new 1024×768 photo.jpg image, and we want to dynamically resize it to 640×480 pixels.

GD

In the example below, we have to call six functions, and possibly perform some calculations if we have variable aspect ratio.

$im = imagecreatefromjpeg('photo.jpg');

$ox = imagesx($im);
$oy = imagesy($im);  

$nx = 640;
$ny = 480;

$nm = imagecreatetruecolor($nx, $ny);  

imagecopyresized($nm,$im,0,0,0,0,$nx,$ny,$ox,$oy);  

imagejpeg($nm, 'photo.jpg');

ImageMagick

IM (short for ImageMagick) has a nice wrapper, called Imagick – a native PHP extension to create and modify images using the ImageMagick API. The only downside is: you will likely have to install it from PECL, which can sometimes be a problem for shared hosting.

$image = new Imagick('photo.jpg');
$image->resizeImage(640, 480, imagick::FILTER_LANCZOS, 0.9);

Even simpler, command-line usage with PHP (this is what we are going to use):

exec('mogrify -resize 640x480 photo.jpg');

That’s it! Excellent.


Installing ImageMagick

Although nearly every good hosting company has ImageMagick installed, you probably don’t have one on a local machine, simply because it isn’t shipped with PHP.
Installing ImageMagick is a cinch, though. Go to the ImageMagick Download page, choose your platform (Unix/Mac/Win), and select recommended package. Simply follow the simple instructions; you can’t make a mistake here.

Once finished, go to your terminal/command-prompt, type in convert and hit Enter, If you receive a list of options instead of “Command not found”, you’re good go! Note that you don’t need to configure anything in PHP.


How Does Instagram Work?

Well, to be honest, I don’t know what system the Instagram team are using for image processing. ImageMagick is also available for iOS; perhaps that is the magic of how Instagram works? To quote Kevin Systrom, Instagram CEO and co-founder:

It’s really a combination of a bunch of different methods. In some cases, we draw on top of images, in others we do pixel math. It really depends on the effect we’re going for.

For instance, Lomo-fi really isn’t much more than the image with boosted contrast. Whereas Toaster is one of the most complex (and slow, yet popular) filters we have with multiple passes and drawing.

I’d give up more info, but it’s our secret sauce :) Maybe some day…

“Maybe some day…” isn’t good enough for us, Mr Systrom. Challenge accepted!


Show Me Teh Codez!

We are going to mimic gotham (return of gotham), toaster (the complex one), nashville (the popular one), lomo (lomo-fi isn’t that good) and kelvin (lord kelvin – original) filters.

Instagraph – the PHP Class

I have created a little PHP wrapper class to make the process of filtering images as simple as possible. In these filters, as you know, we have lots of…

  • colortone: will color tone an image in highlights and/or shadows. For example, we want to change black to purple.
  • vignette: edges of photo fade out or desaturate gradually. We can even reverse this, or use colors for vignette.
  • border: will add a border to the photo. For example, we want a white or black or any color border of a certain width; note that the width of the border will add up to the photo dimensions.
  • frame: will read specified frame and stretch in to fit to photo. We need this for the Nashville and kelvin filters.
  • tempfile: creates temporary file (copy of original image), to work with.
  • output: simply renames the working copy.
  • execute: we will send all commands through this method to prevent errors that can occur while working with the shell.

I’ve made all of these mentioned, so we can skip to fun part. Create a new file, called instagraph.php, and copy & paste the code below.

/**
 * Instagram filters with PHP and ImageMagick
 *
 * @package    Instagraph
 * @author     Webarto <dejan.marjanovic@gmail.com>
 * @copyright  NetTuts+
 * @license    http://creativecommons.org/licenses/by-nc/3.0/ CC BY-NC
 */
class Instagraph 
{
    
    public $_image = NULL;
    public $_output = NULL;
    public $_prefix = 'IMG';
    private $_width = NULL;
    private $_height = NULL;
    private $_tmp = NULL;
        
    public static function factory($image, $output)
    {
        return new Instagraph($image, $output);
    }
        
    public function __construct($image, $output)
    {
        if(file_exists($image))
        {
            $this->_image = $image;
            list($this->_width, $this->_height) = getimagesize($image);
            $this->_output = $output;
        }
        else
        {
            throw new Exception('File not found. Aborting.');
        }
    }

    public function tempfile()
    {
        # copy original file and assign temporary name
        $this->_tmp = $this->_prefix.rand();
        copy($this->_image, $this->_tmp);
    }
    
    public function output()
    {
        # rename working temporary file to output filename
        rename($this->_tmp, $this->_output);
    }

    public function execute($command)
    {
        # remove newlines and convert single quotes to double to prevent errors
        $command = str_replace(array("\n", "'"), array('', '"'), $command);
        $command = escapeshellcmd($command);
        # execute convert program
        exec($command);
    }
    
    /** ACTIONS */
    
    public function colortone($input, $color, $level, $type = 0)
    {
        $args[0] = $level;
        $args[1] = 100 - $level;
        $negate = $type == 0? '-negate': '';

        $this->execute("convert 
        {$input} 
        ( -clone 0 -fill '$color' -colorize 100% ) 
        ( -clone 0 -colorspace gray $negate ) 
        -compose blend -define compose:args=$args[0],$args[1] -composite 
        {$input}");
    }

    public function border($input, $color = 'black', $width = 20)
    {
        $this->execute("convert $input -bordercolor $color -border {$width}x{$width} $input");
    }

    public function frame($input, $frame)
    {
        $this->execute("convert $input ( '$frame' -resize {$this->_width}x{$this->_height}! -unsharp 1.5×1.0+1.5+0.02 ) -flatten $input");
    }
    
    public function vignette($input, $color_1 = 'none', $color_2 = 'black', $crop_factor = 1.5)
    {
        $crop_x = floor($this->_width * $crop_factor);
        $crop_y = floor($this->_height * $crop_factor);
        
        $this->execute("convert 
        ( {$input} ) 
        ( -size {$crop_x}x{$crop_y} 
        radial-gradient:$color_1-$color_2 
        -gravity center -crop {$this->_width}x{$this->_height}+0+0 +repage )
        -compose multiply -flatten 
        {$input}");   
    }
    
    /** RESERVED FOR FILTER METHODS */
    
}

Instagram Filters

We will go over the filters, one by one; I will explain the necessary PHP methods and Imagemagick commands, including examples. Make sure you update your PHP class with these new methods (paste below RESERVED FOR FILTER METHODS comment). The photo frames are provided in the download package; they are just PNG transparent images without extensions. Feel free to make your own! So let’s begin…

Original

Here we simply have a photo of my dogs enjoying the day at the beach. This is straight out of my camera.

terry and linda on the beach

Gotham

The Gotham filter produces a black&white, high contrast image with bluish undertones. In real life, this would be created with a Holga camera and Ilford X2 film.

public function gotham()
{
    $this->tempfile();
    $this->execute("convert $this->_tmp -modulate 120,10,100 -fill '#222b6d' -colorize 20 -gamma 0.5 -contrast -contrast $this->_tmp");
    $this->border($this->_tmp);
    $this->output();
}

In English: create a working file, load the image into memory, improve brightness a bit, (almost) desaturate, change the remaining colors to deep purple, gamma correction (value below 1 darkens image), add more contrast, add more contrast, and save everything to a file. Add a 20px black border. Simple, eh?

Gotham filter

Toaster

The Toaster filter resembles old Polaroid shots; it features vivid colors with pink/orange glow out of the center. By the words of Instagram CEO, it’s one of the most difficult effects to create; we’ll take his word for it.

public function toaster()
{
    $this->tempfile();
    $this->colortone($this->_tmp, '#330000', 100, 0);

    $this->execute("convert $this->_tmp -modulate 150,80,100 -gamma 1.2 -contrast -contrast $this->_tmp");
    
    $this->vignette($this->_tmp, 'none', 'LavenderBlush3');
    $this->vignette($this->_tmp, '#ff9966', 'none');
        
    $this->output();        
}

In English: create a working file, load the image into memory, change blacks to dark red, enhance brightness, desaturate by a fifth, perform gamma correction (make image brighter), add more contrast, add more contrast, save. Lastly, add a grayish vignette (desaturates edges a bit), and an “inverted” orange vignette for color burn effect.

Tip: You can even add a white border for a full effect; just add $this->border($this->_tmp, 'white'); before $this->output();.

Toaster filter

Nashville

Nashville has a nice washed out 80s fashion photo feel. It produces image with a magenta/peach tint. It additionally adds a frame to get that slide look. It’s easily one of the most popular Instagram filters.

public function nashville()
{
    $this->tempfile();
    
    $this->colortone($this->_tmp, '#222b6d', 100, 0);
    $this->colortone($this->_tmp, '#f7daae', 100, 1);
    
    $this->execute("convert $this->_tmp -contrast -modulate 100,150,100 -auto-gamma $this->_tmp");
    $this->frame($this->_tmp, __FUNCTION__);
    
    $this->output();
}

In English: create a working file, load the image into memory, change blacks to indigo, change whites to peach color, enhance contrast, enhance saturation by half, gamma auto-correction. Add a frame from a PNG file.

Nashville filter

Lomo

Lomography is all about making high contrast photos with vignettes and soft focus (everywhere you go). In real life, they are mostly made with Holga, LOMO LC-A or so called toy cameras (cameras with plastic lens). This effect is pretty easy to recreate; we will simply enhance the red and green channels’ contrast by a third, and add a vignette. Feel free to experiment as you wish.

public function lomo()
{
    $this->tempfile();
    
    $command = "convert {$this->_tmp} -channel R -level 33% -channel G -level 33% $this->_tmp";
    
    $this->execute($command);
    $this->vignette($this->_tmp);
    
    $this->output();
}

Create a working file, load the image into memory, enhance red channel contrast by a third, enhance red channel again, apply a vignette.

Tip: If you prefer lomo effect without vignette, just comment or remove that section of code.

Lomo filter

Kelvin

Named after Lord Kelvin, this effect applies a strong peach/orange overlay, and adds a washed out photo frame.

public function kelvin()
{
    $this->tempfile();
    
    $this->execute("convert 
    ( $this->_tmp -auto-gamma -modulate 120,50,100 ) 
    ( -size {$this->_width}x{$this->_height} -fill 'rgba(255,153,0,0.5)' -draw 'rectangle 0,0 {$this->_width},{$this->_height}' )
    -compose multiply 
    $this->_tmp");
    $this->frame($this->_tmp, __FUNCTION__);

    $this->output();
}

In English: create a working file, load the image into memory, normalize, enhance brightness by a fifth, desaturate by half, create an peach/orange color overlay, and apply the multiply blending mode. Lastly, add a frame, using the PNG file.

Kelvin filter

How to Use

It’s easy to use these effects! I’ll assume that you saved all the code within instagraph.php file. Now, create a file, called filter.php and copy the code below that suits you.

If you want to apply only one filter on an image, you can do it this way:

require 'instagraph.php';

try
{
    $instagraph = Instagraph::factory('input.jpg', 'output.jpg');
}
catch (Exception $e) 
{
    echo $e->getMessage();
    die;
}

$instagraph->toaster(); // name of the filter

That’s it! Now, if you want to apply all filters to one image, use this code:

require 'instagraph.php';

try
{
$instagraph = Instagraph::factory('input.jpg', 'output.jpg');
}
catch (Exception $e) 
{
    echo $e->getMessage();
    die;
}

// loop through all filters

foreach(array('gotham', 'toaster', 'nashville', 'lomo', 'kelvin') as $method)
{
    $instagraph->_output = $method.'.jpg'; // we have to change output file to prevent overwrite
    $instagraph->$method(); // apply current filter (from array)
}

Now, just open it in your browser and enjoy the results!

Performance

Performance is certainly an important part of every application. Because the average time to apply a filter to an image is roughly 1 second, we can safely say it is pretty fast!


ImageMagick Resources

To learn more about ImageMagick, here’s a list of links to all the commands and options that were used in these filter methods:

  • convert:
  • modulate: vary the brightness, saturation, and hue
  • contrast: enhance or reduce the image contrast
  • size: width and height of image
  • fill: color to use when filling a graphic primitive
  • draw: annotate the image with a graphic primitive
  • compose: set image composite operator
  • channel: apply option to select image channels
  • level: adjust the level of image contrast
  • auto-gamma: automagically adjust gamma level of image
  • gamma: level of gamma correction

Additionally, here’s a list of ImageMagick scripts, tutorials and examples:


Summary

In this tutorial, we learned a bit about Imagemagick, and demonstrated the power of it by creating filters that are similar to the ones generated by Instagram. We created Instagraph!

If you need any help, or need assistance creating additional filters, such as Tilt Shift or Earlybird, let me know within the comments, and I’ll do my best to assist!

Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://twitter.com/kinduff Kinduff

    Very beautiful, I love ImageMagick. Thanks for the script.

    • webarto
      Author

      Thank you for reading :)

  • Esteban

    sir, you are a genius , nice class

    • webarto
      Author

      If I am, you can bee too! :)

      • http://iarmar.com Ibrahim Azhar Armar

        That was real nice encouraging words. and thank you for the tutorial it is awesome.

  • http://Cdgn.co.uk Vic

    I find doing similar manipulations with HTML5 canvas much easier. And if you are into HTML5 iPhone apps you can knack an app similar to instagram in no time.

    • webarto
      Author

      Hi, I don’t know for sure if that is possible. Either way, that is client side, this is server side :)

    • Michael

      @Vic: Let’s see it then, come on, do a tutorial.

  • Kelvin

    Awesome tutorial. I really would like to know how to add the Tilt Shift filter!

  • http://wpcharity.com Moch. Zamroni

    wow magic! :)

    • webarto
      Author

      Magick :)

  • Frank

    I have put my files in localhost folder but when I run filter.php ,the browser window is blank.

    • webarto
      Author

      You should see output.jpg in your folder, I didn’t want to mix HTML with PHP. I will make another example on github.

      • Frank

        thanks! :)

  • erminio ottone

    Any way we can do something lika that in node.js so we can use same js code clientside ?

    • http://jawbfl.blogspot.com Jaw,B

      I don’t think that Node.js can handle canvas :/ !! .. is there DOM manipulation in Node.js ?

      • Rafael

        Canvas manipulate images using theirs bytes.. I don`t think it is in the DOM level.

  • Chris

    Nice tut, maybe it’s worhtwile adding a few more comments to the class as to explain several functions.
    Oh and maybe an example showing a chained statement =)

    Again, nice tut!

    • webarto
      Author

      Definitely, in this tutorial I wanted to make a compromise, instead of fully explaining each function, I covered basics, and concentrated on creating filters (otherwise it would be pretty big tutorial :)). But expect Imagemagick tutorials.

  • http://www.carloscastillo.com.ar Carlos

    I’ve had bad experiences with ImageMagick. The IM commands are not stable, so, for long commands (using a lot of parenthesis and other stuff) you can expect on newer versions (or olders) than the current one you are using to not work.

    I have yet to try with GraphicsMagick which apparently solves the problem and it’s a lot more stable in terms of it’s API.

    I for one would definitely go with GM instead of IM just because of that.

    Carlos

    • webarto
      Author

      You are probably right, but basic commands are pretty much unchanged or backwards compatible. Like you’ve said, complex things are likely to break, but if something is working good, you don’t need to upgrade, even if you do, I’m sure little modifications are all that’s needed.

  • Pavel

    How do I run filter.php if my hosting company doesn’t have imagemagick?

    • webarto
      Author

      Unfortunately, you can’t, you need Imagemagick.

      • http://yourfreetechsupport.com Ruban

        i think you can use some direct host upload versions of imagemagik … cos i hav found one for windows servers in imagemagik’s site…. its like a set of files rather than a self exec package.

  • http://www.luc.at luc

    I tried it on my host’s server and did not see all effects. Lomo, toaster and nashville dont work. There is no vignette or color correction, but the frames are added.

    They have GraphicsMagick version 1.1.11 from 2008. It seems the syntax has changed in the meantime. Channels are not changed in-place but extracted, which renders a greytone result. They also have to be named like “Red” instead of “R”. Just FYI.

    • webarto
      Author

      Yes, that is the exact problem I have with my hosting company (http://instagraph.me/). Script it tested and working as expected with Imagemagick 6.7.5

      • http://www.luc.at luc

        oh, pity!

      • Thomas

        So what version of Imagemagick has this been written for, I’m having the same grey scale issues on the output images? Thanks for the awesome script anyway!

      • Rohir Naik

        I am having the same problem .. But Little different. Can You suggest me somthng.. Your tutorial works nice on WAMP locally.. but when i hosted and try to figure out…

        Nashville,Kelvin changes its color but no frame and Tilt Shift completety Not working
        My Server has : Version: ImageMagick 6.7.1-7 2012-07-31 Q16
        Localhost: Version: ImageMagick 6.5.9-0 2010-01-11 Q16

        Any suggestion to do ?

    • webarto
      Author

      Up and running :) http://instagraph.me/

  • http://www.aplaceformyhead.co.uk Matt Fairbrass

    I am a big fan of Instagram so I had to give this tutorial a read. Great tutorial, very interesting how with a little know how you can produce some really creative effects in just a few lines of code. Thanks for sharing!

    • webarto
      Author

      Although I haven’t nailed exact “formula” (had about one day to figure it out), with little research you can make exact filters, with practically same amount of code, you just have to play with values :)

  • Jose Gomez

    hey, i have a question, the imagick extension that comes built-in in Zend Server works for this?

    • webarto
      Author

      Only thing you have to have is Imagemagick installed on your server. You don’t need any extension. This uses command line (exec/system from PHP) to interact with Imagemagick.

  • Brad

    Now that’s some great stuff

    • webarto
      Author

      Thanks.

  • http://baylorrae.com Baylor Rae’

    I recommend installing ImageMagick through Homebrew if your using a mac (and possibly linux). I’m not great at compiling things from source and found Homebrew to make it an easy process.

    Information about Homebrew
    http://mxcl.github.com/homebrew/

    Fixes a problem that I had when installing ImageMagick
    http://stackoverflow.com/a/7340280/467546

    • webarto
      Author

      Thanks, helpful links.

  • http://pavel.shimansky.ru/ Pavel

    I run filter.php on my website, but I can’t see any filters applied to my image. What am I doing wrong?

    • webarto
      Author

      You should see output.jpg in your webserver root (script by itself doesn’t display anything, I will fix that example).

      Here is the live demo: http://instagraph.me/ (imagemagick on server is pretty old, I’m waiting my hosting company to upgrade, because filters don’t work as expected, it should work as expected in day-two)

  • Kelvin

    awesome! Can you show us the Tilt Shift filter?

  • http://www.lotusmarketing.ca Lotus Marketing

    Good tutorial, I’ve never modified images with PHP, I did’nt know we could do this kind of stuff. Quite impressive.

    • webarto
      Author

      Basically, you can do everything with PHP, directly on indirectly. You can use any C (or any on your system) program from PHP, just like in this tutorial we call Imagemagick to process for example, image uploaded via PHP.

  • http://www.warpconduit.net Josh

    Beautiful work on reverse engineering these Instagram methods! I find the real power in ImageMagick is being able to work with very large images, specifically resizing, whereas GD will eat up all the PHP memory available and error out.

    • webarto
      Author

      Yes, it is external process, and it is much more optimized for any sort of image manipulation. Thanks :)

  • Leandro

    Great work!

    • webarto
      Author

      Thanks, glad you like it.

  • pierre

    Btw, most of the color/channels filters can be realized using imagefitler (http://www.php.net/imagefilter) or matrix (www.php.net/manual/en/function.imageconvolution.php).

    About GD eating memory, well… imagemagick does not use PHP memory management, so it is a bit like saying, heh, I do not want to know how much mem the apps will use on my servers ;-)

  • http://www.netsi.dk/wordpress Sten Hougaard

    Hi,
    I have downloaded, unpacked and uploaded to my php website, but I only get a untouched version of the original… Also it generates a new image every time I run a filter (look here: http://screencast.com/t/OKdCjyaunK)

    Am I doing something wrong?

    /Sten

    • webarto
      Author

      I guess you are not doing anything wrong. I assume your Imagemagick version is out of date. http://instagraph.me/ will be fully functioning so you don’t have to bother with demo. Also, I will add http://instagraph.me/ to github to show how can web service be made out of this.

  • http://khimoc.com Tran Dinh Khanh

    Hi there,
    I really really like picyou (picyou.com) filters.
    Could you please clone them to Instagraph?

    Thanks for greatest tutorial ever!

    • webarto
      Author

      Hi, thanks. It sure can be done, maybe we’ll make part 2 of tutorial with 5 more filters and more code explanation, if not, I will do my best to add new filter once in a while.

      • http://khimoc.com Tran Dinh Khanh

        Thanks.
        I will stay turned.

  • http://twitter.com/jakerocheleau Jake Rocheleau

    Yea this is super impressive.

    I’d love to implement something simple like Broderick’s http://luxogram.co/

  • Ktee

    I wanted to have a demo when I first saw this article and here it is now!!
    Thank you so much for the great article!!

  • http://sanchothefat.com Robert O’Rourke

    Hey, I’ve made this into a WordPress plugin – it’s a rough prototype for now but it works!

    https://github.com/sanchothefat/wp-instagraph

  • http://jamesbanks.me James

    Cool tutorial. Can anyone provide me with a list of good hosting providers that have the latest version of Imagemagick installed?

    • http://yourfreetechsupport.com Ruban

      Mediatemple grid service works…. really :-) i hv tried

  • Manish Dudeja

    Hey buddy, Nice post!!!!

    I was looking for the same. Will give it a try.

    I was wondering if it is possible to create pencil sketch of images with this library of techniques explained above. PHP has a function in GD library for the same but it was not that much useful. Quality of the generated pic is very low, not eye-caching.

    Looking forward.

  • Thein Hla Maw

    Thank you very much for great tutorial. I am a fan of “Early Birds” filter. Can you at it in next version of http://instagraph.me/ ? One suggestion is it would be nice if you shows filter names in Step 2. Select Filter in http://instagraph.me/.

  • http://theindustry.cc Jared Erondu

    Instagram is by far one of the best social applications for iOS (whoops, and Android). Although I think creating some filters would be lovely, I’m not sure I’d like to many more added. Think about it. If there are 50 options for filters within the app, one of two things will happen. Either you’ll spend 15 minutes going through each one (newbies), or you’ll just use your favorite, a.k.a., default.

    Nevertheless, I know that’s not the idea behind this post. Creating filters with PHP just goes to show how the limits behind most web technologies are gradually dying. PHP5, CSS3, HTML5, etc., are capable of much more than we give then credit for!

  • Muneeb

    hi @webarto

    i have downloaded your demo and installed the ImageMagick and the convert command work properly in shell
    but when i play with the demo the output image does not have any effects , the code produce the image but with no effects , it was the same image(that dog image) that is already appearing on the webpage

    • KD

      you want to add extension on php.ini file and restart your server

  • Johnny

    Hi,
    First, thanks a lot!!
    i’ve got a question, inside the folder, besides the phps there are some files such as kelvin and nashville, these files have no extention, so i don’t know how to use them. What is their function? Because the others filters don’t have any files like these.

    Thanks !

    • webarto
      Author

      Hey, those are frames for nashville and kelvin, there are just PNG files without extension, you can rename them (add PNG extension), and you will see for yourself.

      • Johnny

        Thnaks!!

  • http://vivekipedia.tumblr.com Vivek

    This is nice. I think Facebook could have saved a billion dollars. :D

    • webarto
      Author

      Hehe, I would settle for 0.1% of deal :)

  • Carlson

    This is a awesome tutorial.

    My server don’t allowed me use to exec function for security reasons. Can you show / create a script to use IMagick extension?

    Thanks

    • webarto
      Author

      Thanks, unfortunately, you IMagick is not complex enough to perform these operations.

  • http://www.carlosbaeza.net Carlos

    Doesn’t work for me :(

    • webarto
      Author

      Sorry, what is the problem?

      • http://www.carlosbaeza.net Carlos

        Hello there, i’ve contacted you via Twitter, you told me that the version of ImageMagick was too old in the server that i have the script hosted, and they responce me that i must import to some “bin” folder in my public_html the files and redirect them inside the php.ini. do you know something about this?.

        have my best regards and thank you for your time :)

      • http://www.carlosbaeza.net Carlos

        hello webarto,

        i’ve installed a new version of imagemagick here: http://goo.gl/0Mo7J

        php.ini sayd:

        imagick module version: 3.0.1
        imagick classes: Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator
        ImageMagick version: ImageMagick 6.7.1-7 2012-05-02 Q16 http://www.imagemagick.org

        and the Nashville and Kelvin filter ins’t working properly, because applyes the filter but not the frame…

        plase help me, regards

  • alantakashi

    Nice tutorial and it is really great. But i had the sample problem @Muneeb faced. Downloaded the files, installed ImageMagick and the convert command work with no error. Open the index.html and the output image does not have any effects, output.jpg is display but with no effects, it was the same image as the input.jpg

  • http://www.techispeaks.com Kathirason

    Outstanding work :)

  • edwin

    Hello. I download your application, install the software ImageMagic, run it on localhost and it becomes me not to Instagram photo.

    my OS is windows 7 64 bit.

  • http://www.milankragujevic.com/ Milan

    @edwin ImageMagick works only on unix / linux.

  • pubstub

    nice script, kudos to you.

    I eventually got the basic site running on Ubuntu VM, although i had to adjust permissions for the output.jpg file to allow it to be written to the web folder.

    i’ve used imagemagick extensively over the past decade or so but only for command line based stuff, i’m new[ish] to php stuff so this was an interesting tutorial to follow.

    the tilt_shift_before example looks brilliant post “tilt shift”… like little toy cars.

  • http://www.cosmetique-biologique.net melvita

    Thanks a lot, that s perfect for my app.

  • http://www.gungyi.com Kevin

    Thanks very much, You made very nice scripts.

    How do you know the way Instagram create their filters? For example, the “Apollo” and “Hefe”?

  • http://www.jvsoftware.com Javier Villanueva

    Great library hopefully people can contribute and make some extra filters :)

  • aysh

    Thank you!

  • http://www.vueine.com vueine

    I have tested this program.
    But failed.
    The picture has not changed. why?

  • Michael

    Really great tutorial! Saved me a lot of time! I modified the output function a little bit so instead of saving the file to the server the image is returned:

    public function output()
    {

    $fp = fopen($this->_tmp, ‘r’);
    $content = fread($fp, filesize($this->_tmp));
    header(“Content-type: image/jpeg”);
    echo($content);
    unlink($this->_tmp);

    }

    Maybe there are better solutions (without saving / deleting the file) so any suggestion in that direct would be nice. Maybe you can add a parameter whether or not the image is being saved to a file or directly output to the browser.

    Thanks,
    Michael

  • http://roberttilt.name Robert Tilt

    Hi there,
    This looks like it can be very useful. I was just wondering, is instagraph.me still working properly? Whenever I try to use it, I get the following error after clicking Go:

    Not Found
    The requested URL /p/5bd587a44f6db336635deb5f29be1c27 was not found on this server.
    Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

    Cheers!

  • marko

    Nice job!

    To those wondering why filters don’t take effect, this might help you.
    http://stackoverflow.com/questions/9401824/exec-command-doesnt-work-as-expected

    That tells you to prefix `convert` command with something like `/opt/local/bin/`.
    So in my copy of Instagraph class, I added a private property named `$_convert`.

    // The `convert` command with leading path
    private $_convert = ‘/opt/local/bin/convert’;

    Then I replaced every `convert` command with `{$this->_convert}`.


    $this->execute(“{$this->_convert} …

  • Aimee

    The example page still isn’t working – I see someone commented on this back in May with no reply. Is this code still supported? I can’t get the example to work – same error as others have reported but again no answer has been given as to the exact Image Magick version needed to make it work. Anyone know anything? I’d really like to be able to use this!

  • sebastien

    demo doesn’t work