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 (34)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

May 17, 2008
Learn HTML forms
About
 
May 16, 2008
Who Are Your Top Friends on Facebook?
About
 
May 15, 2008
Reader Question - Would you host your client's work on your website?
About
 
May 15, 2008
How to Create an Ajax Autocomplete Text Field: Part 6
WebReference.com
 
May 14, 2008
Poll: Are the browser safe colors still needed?
About
 
May 14, 2008
Google Doctype launched
About
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /PHP

PHP frontend to ImageMagick 

  Views:    22441
  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: firstback2 3 4 5 forwardlast
The Article

What is ImageMagick?

ImageMagick is a powerful set of image manipulation utilities. It can read, write and manipulate images in many image formats. It can resize, rotate, sharpen, color reduce or add any other special effect to your images. And, best of all, ImageMagick is directly available from the command line. In this article, we will write a script to make it available from the query string. You can then use it, for example, to automatically generate thumbnails of your images.

What our script will do

We will write a script that we can copy-paste in a directory with images and that enables us to use ImageMagick's convert utility on each of the images in that directory. The script will enable us to give convert commands by changing the query string.
Maybe a simple example will better explain this idea. You've got an image:
http://wwww.example.com/img/image.jpg. You copy the ImageMagick script magick.phpto the same directory. The image is now also available as http://www.example.com/img/magick.php/image.jpg. So far, your image hasn't changed. Now, imagine you want a thumbnail of the image with a width of exactly 200 pixels. You can get that image by requesting the url: http://www.example.com/img/magick.php/image.jpg?resize(200).

On receiving a request, the script will:

1. Parse the query string
2. Convert the query string to an ImageMagick command string
3. Run ImageMagick on the image
4. Send the modified image to the browser.

As you see, the script will run ImageMagick for every request. This isn't very efficient. As you will probably use just a few commands (e.g. thumbnail and original image) in your html files, caching the output will speed up the system. We will add a point 5 to the list. The output of ImageMagick should be cached. The script should send the cached image if it exists, so ImageMagick won't be generating the same image over and over again.

Pages: firstback2 3 4 5 forwardlast

Similar/related articles:


 
  Sponsors