Quercus: Image Library example

From Resin 3.0

Revision as of 15:17, 12 June 2006 by Megacz (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Here's a short example of how to use the Quercus image library. This example fetches a fine image of a young man demonstrating his martial arts skills in an unlikely environment. It then applies a convolution to the image, and adds a much-needed embellishment to the scene and displays the resulting image.

Note that this example uses imageconvolution(), which is one of a number of functions which mod_php will not make available unless compiled with special flags. Many prebuilt binary packages are not compiled this way, so most php installations can't use these functions. With Quercus, you always have access to all of the functionality all of the time -- there is no compile-time configuration to worry about.

Here's the code; it downloads the images across the network (using Quercus' equivalent of "fopen wrappers"), so the script is self-contained:

  $image = imagecreatetruecolor(576, 480);
  # fetch the image of a young man with REAL ULTIMATE POWER
  $picture = imagecreatefromjpeg("ht tp://www.realultimatepower.net/ninja/kidgarbage.jpg");
  imagecopy($image, $picture, 0, 0, 0, 0, 576, 480);
  # apply a convolution
  $matrix = array(    array(  1, -1, -1 ),
                      array( -1,  5, -1 ),
                      array( -1, -1,  1 ) );
  $divisor = 1;
  $offset = 0;
  imageconvolution($image, $matrix, $divisor, $offset);
  # laser beams.  everybody needs laser beams.
  $red = imagecolorallocate($image, 255, 0, 0);
  imagesetthickness($image, 3);
  imageline($image, 334, 161, 0, 300, $red);
  imageline($image, 351, 159, 0, 300, $red);
  # set the output type and send the image to the client.
  header("Content-type: image/png");

Note that you'll need Resin 3.0.20 or the 2006/06/02 snapshot in order to run this properly.

Personal tools