Location: PHPKode > scripts > GD Image Manipulation > gd-image-manipulation/test.php
<?php
/* Test file for GDImageManipulation.class.php
 *
 * This test file shows the manipulation capacities of the class.
 * To see exactly what the commands do, they are not stacked. Of course,
 * you can call different methods prior to pulling the data out of the 
 * class.
 *
 * See the upcoming documentation for details.
 *
 * IMPORTANT:
 * Do not call this script with Internet Explorer, the results will be
 * frustrating since Microsoft doesn't support the data:-uri correctly.
 * Use Firefox instead.
 * The data:-uri is used to avoid tons of images written to disk. Of course,
 * you could save the images as files and embed them with a file: or http:-uri
 * as well.
 *
 * The output of this file is impressively large due to the embedded images
 * (about 1 MB) so you better not call this from anything but your local 
 * environment. You have been warned.
 *
 */
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">

<html>

   <head> 
      <title>GDImageManipulation</title>
   </head>

   <body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<?php

require_once('GDImageManipulation.class.php');
$filename="300.png";

function recycle() {
    global $imageManipulation;
    global $filename;
    unset($imageManipulation);
    $imageManipulation = new GDImageManipulation();
    $imageManipulation->set_image_asFile($filename);
    return $imageManipulation;
} 

$imageManipulation = new GDImageManipulation();

echo "<h1>Welcome to GDImageManipulation!</h1><hr />";
echo "<table border=1>";


// fit_width
// usage: fit_width(int $pixel [,bool $enlarge_small_images]);
//
echo "<tr><td><br />Original</td><td><br />fit_width('100')</td></tr>";
echo "<tr><td><img src=\"".$filename."\" /></td><td>";
$imageManipulation = recycle();
$imageManipulation->fit_width('100', true);
echo $imageManipulation->get_inlineTag_png('png');
echo "</td></tr>";

// fit_height
// usage: fit_height(int $pixel [,bool $enlarge_small_images]);
//
echo "<tr><td><br />Original</td><td><br />fit_height('100')</td></tr>";
echo "<tr><td><img src=\"".$filename."\" /></td><td>";
$imageManipulation = recycle();
$imageManipulation->fit_height('100', true);
echo $imageManipulation->get_inlineTag_png('png');
echo "</td></tr>";

// resize I
// usage: resize(float $factor)
//
echo "<tr><td><br />Original</td><td><br />resize('1.5')</td></tr>";
echo "<tr><td><img src=\"".$filename."\" /></td><td>";
$imageManipulation = recycle();
$imageManipulation->resize('1.5');
echo $imageManipulation->get_inlineTag_png('png');
echo "</td></tr>";

// resize II
// Please see that shrinking is also supported.
echo "<tr><td><br />Original</td><td><br />resize('0.5')</td></tr>";
echo "<tr><td><img src=\"".$filename."\" /></td><td>";
$imageManipulation = recycle();
$imageManipulation->resize('0.5');
echo $imageManipulation->get_inlineTag_png('png');
echo "</td></tr>";

// convert_sepia
// usage: convert_sepia()
//
echo "<tr><td><br />Original</td><td><br />convert_sepia()</td></tr>";
echo "<tr><td><img src=\"".$filename."\" /></td><td>";
$imageManipulation = recycle();
$imageManipulation->convert_sepia();
echo $imageManipulation->get_inlineTag_png('png');
echo "</td></tr>";

// convert_grayscale
// usage: convert_grayscale()
//
echo "<tr><td><br />Original</td><td><br />convert_grayscale()</td></tr>";
echo "<tr><td><img src=\"".$filename."\" /></td><td>";
$imageManipulation = recycle();
$imageManipulation->convert_grayscale();
echo $imageManipulation->get_inlineTag_png('png');
echo "</td></tr>";

// convert_colorize r
// usage: convert_colorize(int $red[0...255], int $green[0...255], int $blue[0...255]);
echo "<tr><td><br />Original</td><td><br />convert_colorize(255,0,0)</td></tr>";
echo "<tr><td><img src=\"".$filename."\" /></td><td>";
$imageManipulation = recycle();
$imageManipulation->convert_colorize(255,0,0);
echo $imageManipulation->get_inlineTag_png('png');
echo "</td></tr>";

// convert_colorize g
echo "<tr><td><br />Original</td><td><br />convert_colorize(0,255,0)</td></tr>";
echo "<tr><td><img src=\"".$filename."\" /></td><td>";
$imageManipulation = recycle();
$imageManipulation->convert_colorize(0,255,0);
echo $imageManipulation->get_inlineTag_png('png');
echo "</td></tr>";

// convert_colorize b
echo "<tr><td><br />Original</td><td><br />convert_colorize(0,0,255)</td></tr>";
echo "<tr><td><img src=\"".$filename."\" /></td><td>";
$imageManipulation = recycle();
$imageManipulation->convert_colorize(0,0,255);
echo $imageManipulation->get_inlineTag_png('png');
echo "</td></tr>";

// convert_brightness I
// usage: convert_brightness(int $level);
//
echo "<tr><td><br />Original</td><td><br />convert_brightness(100)</td></tr>";
echo "<tr><td><img src=\"".$filename."\" /></td><td>";
$imageManipulation = recycle();
$imageManipulation->convert_brightness(100);
echo $imageManipulation->get_inlineTag_png('png');
echo "</td></tr>";

// convert_brightness II
echo "<tr><td><br />Original</td><td><br />convert_brightness(-100)</td></tr>";
echo "<tr><td><img src=\"".$filename."\" /></td><td>";
$imageManipulation = recycle();
$imageManipulation->convert_brightness(-100);
echo $imageManipulation->get_inlineTag_png('png');
echo "</td></tr>";

// convert_contrast I
// usage: convert_contrast(int $level);
//
echo "<tr><td><br />Original</td><td><br />convert_contrast(50)</td></tr>";
echo "<tr><td><img src=\"".$filename."\" /></td><td>";
$imageManipulation = recycle();
$imageManipulation->convert_contrast(50);
echo $imageManipulation->get_inlineTag_png('png');
echo "</td></tr>";

// convert_contrast II
echo "<tr><td><br />Original</td><td><br />convert_contrast(-100)</td></tr>";
echo "<tr><td><img src=\"".$filename."\" /></td><td>";
$imageManipulation = recycle();
$imageManipulation->convert_contrast(-100);
echo $imageManipulation->get_inlineTag_png('png');
echo "</td></tr>";

// convert_edgedetect
// usage: convert_edgedetect();
//
echo "<tr><td><br />Original</td><td><br />convert_edgedetect()</td></tr>";
echo "<tr><td><img src=\"".$filename."\" /></td><td>";
$imageManipulation = recycle();
$imageManipulation->convert_edgedetect();
echo $imageManipulation->get_inlineTag_png('png');
echo "</td></tr>";

// convert_emboss
// usage: convert_emboss();
//
echo "<tr><td><br />Original</td><td><br />convert_emboss()</td></tr>";
echo "<tr><td><img src=\"".$filename."\" /></td><td>";
$imageManipulation = recycle();
$imageManipulation->convert_emboss();
echo $imageManipulation->get_inlineTag_png('png');
echo "</td></tr>";

// convert_gaussian_blur
// usage: convert_gaussian_blur();
//
echo "<tr><td><br />Original</td><td><br />convert_gaussian_blur()</td></tr>";
echo "<tr><td><img src=\"".$filename."\" /></td><td>";
$imageManipulation = recycle();
$imageManipulation->convert_gaussian_blur();
echo $imageManipulation->get_inlineTag_png('png');
echo "</td></tr>";

// convert_selective_blur
// usage: convert_selective_blur();
//
echo "<tr><td><br />Original</td><td><br />convert_selective_blur()</td></tr>";
echo "<tr><td><img src=\"".$filename."\" /></td><td>";
$imageManipulation = recycle();
$imageManipulation->convert_selective_blur();
echo $imageManipulation->get_inlineTag_png('png');
echo "</td></tr>";

// convert_mean_removal
// usage: convert_mean_removal();
//
echo "<tr><td><br />Original</td><td><br />convert_mean_removal()</td></tr>";
echo "<tr><td><img src=\"".$filename."\" /></td><td>";
$imageManipulation = recycle();
$imageManipulation->convert_mean_removal();
echo $imageManipulation->get_inlineTag_png('png');
echo "</td></tr>";

// convert_smooth I
// usage: convert_smooth(int $level);
//
echo "<tr><td><br />Original</td><td><br />convert_smooth(50)</td></tr>";
echo "<tr><td><img src=\"".$filename."\" /></td><td>";
$imageManipulation = recycle();
$imageManipulation->convert_smooth(50);
echo $imageManipulation->get_inlineTag_png('png');
echo "</td></tr>";

// flip_vertical
// usage: flip_vertical();
//
echo "<tr><td><br />Original</td><td><br />flip_vertical()</td></tr>";
echo "<tr><td><img src=\"".$filename."\" /></td><td>";
$imageManipulation = recycle();
$imageManipulation->flip_vertical();
echo $imageManipulation->get_inlineTag_png('png');
echo "</td></tr>";

// flip_horizontal
// usage: flip_horizontal();
echo "<tr><td><br />Original</td><td><br />flip_horizontal()</td></tr>";
echo "<tr><td><img src=\"".$filename."\" /></td><td>";
$imageManipulation = recycle();
$imageManipulation->flip_horizontal();
echo $imageManipulation->get_inlineTag_png('png');
echo "</td></tr>";

// rotate I
// usage: rotate(float $angle, int $backgroundcolor_red, int $backgroundcolor_blue, int $backgroundcolor_green)
echo "<tr><td><br />Original</td><td><br />rotate(45, 255, 255, 255)</td></tr>";
echo "<tr><td><img src=\"".$filename."\" /></td><td>";
$imageManipulation = recycle();
$imageManipulation->rotate(45, 255, 255, 255);
echo $imageManipulation->get_inlineTag_png('png');
echo "</td></tr>";

// rotate II
// Please note that negative angles work correctly.
echo "<tr><td><br />Original</td><td><br />rotate(-135, 255, 0, 0)</td></tr>";
echo "<tr><td><img src=\"".$filename."\" /></td><td>";
$imageManipulation = recycle();
$imageManipulation->rotate(-135, 255, 0, 0);
echo $imageManipulation->get_inlineTag_png('png');
echo "</td></tr>";

echo "</table>";
?>


   </body>
</html>
Return current item: GD Image Manipulation