iNET Interactive - Online Advertising Agency
          
   Home    Authors    About    Login    Contact Us
   Search:   
Advanced Search     
  Articles

  ASP (26)
  ASP.NET (19)
  C and C++ (4)
  CFML (2)
  CGI and Perl (16)
  Flash (2)
  Java (7)
  JavaScript (28)
  PHP (92)
  MySQL (13)
  MSSQL (3)
  HTML (35)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

July 3, 2008
Poll: Which Web editor do you use?
About
 
July 3, 2008
Book Review: Head First JavaScript
WebReference.com
 
July 3, 2008
10 Things You Can Do With a Wiki
About
 
July 2, 2008
Web Host Reviews - 10 New Reviews
About
 
July 2, 2008
14 Reasons You Should Join a Social Network
About
 
July 1, 2008
Mark Boulton's Freelance Design Secrets
SitePoint
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /PHP

PHP frontend to ImageMagick 

  Views:    23589
  Votes:    3
by Gijs van Tulder 1/17/04 Rating: 

Synopsis:

In this article, we will write a script to connect ImageMagick to PHP. You can then generate thumbnails and other versions of your images on-the-fly, by just editing the url.
Pages: firstback1 3 4 5 forwardlast
The Article

Commands

You can use the standard commands/options of ImageMagick's convert utility. The command is followed by the command's parameters. These parameters are enclosed in brackets. Multiple commands are separated by a plus sign.

ImageMagick uses < and > in some parameters. You can't use these in html-documents. Instead of < and >, you may use { and } in your query string. The scripts then converts { to < and } to >.
Here are a few example convert commands and their query equivalent.

 Command line    Query string

 -resize "100x150" 

 ?resize(100x150)

 -resize "800x600>" -roll "90" 

 ?resize(800x600})+roll(90)

 -flip -resize "800x600>" -flop 

 ?flip+resize(800x600})+flop

Extra commands

The long list of ImageMagick commands didn't contain some things I wanted to do. I added three 'extra' commands to the script to do this.

part

The first of these commands is part(widthxheight) . With ImageMagick's cropcommand, it is possible to get a part of the image. Unfortunately, this command only accepts absolute parameters. It can crop wby hpixels, starting xpixels from the left and ypixels from the top of the image. But what if I want to get 100x100 pixels from the center of the image? That's impossible if I don't know the size of the image.

Enter the part command. It resizes the image to match either the preferred width or the preferred height. Then it crops the image to get the center part of that resized image. And that's what I wanted to do.

colorizehex

ImageMagick's colorize command accepts only decimal RGB numbers, on a 0 to 100 scale. To colorize with red gives colorize 100/0/0. This isn't ideal for web use, since html uses hex codes to identify colors. The colorizehex(hex) command does accept hex colors. It converts them to the ImageMagick notation. Example: a red colorize is done with colorizehex(FF0000).

type

The type(type) is available in ImageMagick. It's just not a part of the commands, but is appended to the name of the output file (e.g. jpg:output.jpg). I wanted to include it in the query string, so I made it a command. You can now convert the image to jpeg by using type(jpg) in your query.

Pages: firstback1 3 4 5 forwardlast

Similar/related articles:


 
  Sponsors