ImageMagick

Introduction

In 1999 the ImageMagick Studio LLC developed a graphical application named ImageMagick for working on images. ImageMagick is a software to create, edit, compose, or convert bitmap images. It can read and write images in a variety of formats including PNG, JPEG, JPEG-2000, GIF, TIFF and SVG.

Using ImageMagick we can create and edit images dynamically and show the

result online on our desired URLs or locally on our computer. Another interesting feature of ImageMagick is its ability to work on animated file formats. It is possible to use all the ImageMagick effects available for still images on animated formats.

Installation

Platform: Fedora Core 3 x86_64 RPM

Download Links

http://www.imagemagick.org/download/linux/fedora/x86_64/ImageMagick-6.2.5-5.x86_64.rpm

ftp://ftp.imagemagick.org/pub/ImageMagick/linux/fedora/x86_64/

ImageMagick-6.2.6-5.x86_64.rpm

 

Platform: Mac OS X

Download Links

http://www.imagemagick.org/download/binaries/ImageMagick-powerpc-apple-

darwin8.5.0.tar.gz

ftp://ftp.imagemagick.org/pub/ImageMagick/binaries/ImageMagick-powerpc-apple-darwin8.5.0.tar.gz

 

Platform: Solaris Sparc 2.10

Download Links

http://www.imagemagick.org/download/binaries/ImageMagick-sparc-sun-

solaris2.10.tar.gz

ftp://ftp.imagemagick.org/pub/ImageMagick/binaries/ImageMagick-sparc-sun-solaris2.10.tar.gz

 

Platform:FreeBSD 4.8

Download links

http://www.imagemagick.org/download/binaries/ImageMagick-i386-unknown-

freebsd4.8.tar.gz

ftp://ftp.imagemagick.org/pub/ImageMagick/binaries/ImageMagick-i386-unknown-freebsd4.8.tar.gz

 

Platform: Windows (Dynamic at 16 bits-per-pixel)

Download links

http://www.imagemagick.org/download/binaries/ImageMagick-6.2.6-5-Q16-windows-dll.exe

ftp://ftp.imagemagick.org/pub/ImageMagick/binaries/ImageMagick-6.2.6-5-Q16-windows-dll.exe

 

Installation steps on windows

  1)   Double click the installation setup file.

   2) Fill the Basic User Info Details (a)

   3) License agreement (b)

   4) Set the Destination for programming installation (d)

   5) Finally Choose the Name for the Program (e).

 

The following screen steps are very important based on our programming interfaces.

 

 

The above screen has additional supported file formats based on our programming languages. These are called delegates in Image Magick.

 

 

Image Magick application Interfaces are available based on programming languages as follows

 

The following program helps to resize the image using php with image magick

<?php

  $image="logo.png";

  $size="70x46";

 $cmd ="mogrify -resize $size $image";

 exec($cmd);

?>

 

Convert the image into black and white

<?php

 

   $x=new insta_filter('logo.png','sample.png');

   $x->tempfile();

    $x->execute("convert $x->_tmp -modulate 120,10,100 -fill '#222b6d' -colorize 20 -gamma 0.5 -contrast -contrast $x->_tmp");

    $x->border($x->_tmp);

    $x->output();

?>

Extract rgb colors from image

<?php

  $cmd2="convert logo: -channel R -separate separate_red.gif";

  $cmd3="convert logo: -channel G -separate separate_green.gif";

  $cmd4="convert logo: -channel B -separate separate_blue.gif";

 exec($cmd2);

 exec($cmd3);

 exec($cmd4);

?>

Combining RGB Channel Images into one rgb Image

<?php

$src1=”separate_red.gif”;

$src2=”separate_green.gif”;

$src3=” separate_blue.gif”;

$final=” rose_combined.gif”;

$cmd5="convert $src1 $src2 $src3 -set colorspace RGB -combine -set colorspace sRGB $final";

exec($cmd5);

?>

output:

 

 

 

Morphology

<?php

$src=” index.jpg”;

$final=”final.gif”;

$cmd="convert $src -channel RG -morphology Thinning:-1 Skeleton +channel $final";

 exec($cmd);

?>

 Output:

Before

After

 

replace white background color with transparent of an image in ImageMagick

 

<?php

$src=”logo.jpg”;

$final=”final.png”;

$cmd="convert $src -transparent white $final”;

 exec($cmd);

?>

Create a movie clip from group of images 

<?php

$final=”animated.mpg”;

$cmd="convert –delay 1 *.jpg $final”;

exec($cmd);

?>

 
Compare the images and result transfer to another image.

<?php

$src1=”index.png”;

$src2=”logo.png”;

$final=”compare.jpg”;

 
$cmd8="compare $src1 $src2  compare.gif";
 exec($cmd8);
?>
 

Converting a PDF to Image and displaying

<?php

$pdf = '/pdf/mypdf.pdf[0]';

$image = new Imagick($pdf);

$image->resizeImage( 200, 200, imagick::FILTER_LANCZOS, 0);

$image->setImageFormat( "png" );

$image->writeImage('pdfAsImage.png');

?>

 

Mogrify vs. Convert

ImageMagick provides two similar tools for manipulating images: convert is the basic image editor and works on one image at a time. mogrify is mostly used for batch image manipulation.

The above options are basic techniques in imagemagick.