A very powerful tool for creating and manipulating images is ImageMagick. With this tools you can create drawings, modify existing images or just process images. The tool is available for Linux, windows and Mac based systems and is free available. Using the command line is Imagemagick the optimal tool to use image functions within your script or application.
Use Imagemagick to watermark your images, to create fancy e-cards or just to convert images into other formats. Basic operations are very easy like
convert resize 50% image.jpg new.png
This simple command will resize your jpg image and safe a copy as some new image in .png format. Just imagine how much code you need with the GD library. As a webmaster you will find ImageMagick with most of the web hosting accounts.
Check Google if you need example code and resources. If you can’t find the information you should try the book “ImageMagick tips and tricks”. This book full of information and tutorials is a good start to learn all basic functions of this powerful tool.
Inside the book you find instructions how to install ImageMagick on different platform and there also basic instructions on how-to install additional fonts. If you’re interested in this feature you should read this article too.
You will find real word examples for each command line tool. Each function has a few lessons of each chapter to train each function with a real world example:
Convert and mogrify
Both functions are used for transformations, while the convert creates a new image is the mogrify function used to change existing images. For examples:
crop an existing image and safe a cropped new version
convert sample.png crop 110x70+60+50 cropped.jpg
draw a line on white background inside a new image
mogrify size 80x100 xcwhite draw 'line 10,10 70,90' line.bmp
Composite and montage
These both functions are used to group or assemble multiple image sequences together like:
Mask an existing logo image with some background and safe it into the result image
composite -compose CopyOpacity logo_mask.png background.png result.png
Other functions like identify, display, import and conjure are explained too, check the book or the IM website for more information.
The book is written to use ImageMagick with php. Use above tools in your PHP code like:
$command = 'convert example.jpg new.png';
Instead of the PHP function exec it’s also possible to process the commands with functions like system, passthru or shell_exec.
After you got all the basic lessons you get some more practice:
- How to call ImageMagick Command-line Utilities within PHP code
- How to Save the Result of an Online Image Processing Task
- How to Start Sessions for our Visitors
- Building a Confirmation-Code Box
- Online Image Water Marking
- A complete E-card application
Learn how to add different text styles to your e-cards. The tutorial includes the complete code for the following features:
- Image gallery
- Image upload / remote copy
- custom text for the e-cards
- fomat text on images
- send the finished e-card by e-mail
The book was released in 2006 but is still “compatible” with current version of ImageMagick.
More ImageMagick resources
Published in: PHP Scripts