Documentation is available at class.imgmagick.php
1 <?php
2 /*
3 METAjour version 1.6 - Content Management System
4 Copyright (C) 2003 IPW Systems A/S
5
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20 $Id: class.imgmagick.php,v 1.1.1.1 2004/09/15 15:33:52 Administrator Exp $
21
22 */
23 class imgmagick {
24
25 function imgmagick($image, $outfile, $cmds) {
26 $convert_path = 'c:/programmer/imagemagick/convert';
27
28 if (!file_exists($image)) {
29 die('ERROR');
30 }
31 preg_match_all('/\+*(([a-z]+)(\(([^\)]*)\))?)\+*/',
32 $cmds,
33 $matches, PREG_SET_ORDER);
34
35 // convert query string to an imagemagick command string
36 $commands = '';
37 foreach ($matches as $match) {
38 // $match[2] is the command name
39 // $match[4] the parameter
40
41 // check input
42 if (!preg_match('/^[a-z]+$/',$match[2])) {
43 die('ERROR: Invalid command.');
44 }
45 if (!preg_match('/^[a-z0-9\/{}+-<>!@%]+$/',$match[4])) {
46 die('ERROR: Invalid parameter.');
47 }
48
49 // replace } with >, { with <
50 // > and < could give problems when using html
51 $match[4] = str_replace('}','>',$match[4]);
52 $match[4] = str_replace('{','<',$match[4]);
53
54 // check for special, scripted commands
55 switch ($match[2]) {
56
57 case 'type':
58 // convert the image to this file type
59 if (!preg_match('/^[a-z]+$/',$match[4])) {
60 die('ERROR: Invalid parameter.');
61 }
62 $new_type = $match[4];
63 break;
64
65 default:
66 // nothing special, just add the command
67 if ($match[4]=='') {
68 // no parameter given, eg: flip
69 $commands .= ' -'.$match[2].'';
70 } else {
71 $commands .= ' -'.$match[2].' "'.$match[4].'"';
72 }
73 }
74 }
75
76 // create the convert-command
77 $convert = $convert_path.' '.$commands.' "'.$image.'" ';
78 if (file_exists($outfile)) @unlink($outfile);
79 if (isset($new_type)) {
80 // send file type-command to imagemagick
81 $convert .= $new_type.':';
82 }
83 $convert .= '"'.$outfile.'"';
84 echo ($convert);
85 exec($convert);
86 }
87 }
88 ?>
Documentation generated on Thu, 9 Jun 2005 06:51:39 +0200 by phpDocumentor 1.2.3