1<?php
2#ini_set('include_path', '.');
3/**
4 * Usage: test.php?driver=XX
5 *
6 */
7// as we're testing we want high error reporting
8error_reporting(E_ALL);
9
10// Where we'll put resulting image and HTML files...
11define('TEST_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR);
12define('TEST_IMAGE_DIR', TEST_DIR . 'images' . DIRECTORY_SEPARATOR);
13define('TEST_OUTPUT_DIR', TEST_DIR . 'tmp' . DIRECTORY_SEPARATOR);
14
15define('FONTS', '/usr/share/fonts/');
16define('FONTS_TTF', FONTS . DIRECTORY_SEPARATOR . 'corefonts' . DIRECTORY_SEPARATOR);
17
18#$lib_path = array('IM' =>)
19
20
21$driver = $_GET['driver'];
22$image = $_GET['image'];
23if (!defined('IMAGE_TRANSFORM_LIB_PATH')) {
24    define('IMAGE_TRANSFORM_LIB_PATH', '/usr/bin/');
25}
26
27if ($driver == 'IM' || $driver == 'NetPBM') {
28    // Assume binaries are in your path
29    #define('IMAGE_TRANSFORM_LIB_PATH', '');
30}
31
32require_once 'Image/Transform.php';
33$im = Image_Transform::factory($driver);
34#var_dump($im);
35if (PEAR::isError($im)) {
36    die($im->message);
37}
38// Load the image
39$im->load(TEST_IMAGE_DIR . $image);
40
41/*
42 * Initialise variables
43 */
44$cmd = isset($_GET['cmd']) ? $_GET['cmd'] : '';
45$angle = isset($_GET['angle']) ? intval($_GET['angle']) : 0;
46$width = isset($_GET['width']) ? intval($_GET['width']) : $im->getImageWidth();
47$height = isset($_GET['height']) ? intval($_GET['height']) : $im->getImageHeight();
48// Text to be added
49$text = isset($_GET['text']) ? $_GET['text'] : 'Sample Text';
50
51/*
52 * Now start.  Switch cmd to find which test to run
53 */
54$cmds = explode('|', $cmd);
55foreach($cmds as $cmd){
56	switch($cmd){
57        case 'addText':
58            $im->addText(array('text' => $text, 'font' => FONTS_TTF . '/arial.ttf'));
59            break;
60    	case 'resize':
61    		$im->resize($width/2, $height/2);
62    		break;
63    	case 'rotate':
64    		$im->rotate($angle);
65    		break;
66        case 'scaleByX':
67            $im->scaleByX($width/2);
68            break;
69        case 'scaleByY':
70            $im->scaleByY($width/2);
71            break;
72        case 'scaleByFactor':
73            $im->scaleByFactor(0.5);
74            break;
75        case 'scaleByPercentage':
76            $im->scaleByPercentage(50);
77            break;
78        default:
79    		trigger_error('No command specified... aborting');
80    } // switch
81}
82
83$im->display(null, 100);
84#$im->save($image_file . '-' . $driver);
85$im->free();
86/*
87 * Now load the image, and:
88 *  a) add text and then resize
89 *  a) resize and then add text
90 * Check the font size is different
91 */
92
93/*
94 * Rotate the image
95 */
96
97?>
98