1 | <?php |
---|
2 | |
---|
3 | class Imagick |
---|
4 | { |
---|
5 | var $source_path = ''; |
---|
6 | var $image_data = array(); |
---|
7 | var $imagemagickdir = ''; |
---|
8 | var $commands = array(); |
---|
9 | var $width = ''; |
---|
10 | var $height = ''; |
---|
11 | |
---|
12 | const INTERLACE_NO = 'none'; |
---|
13 | const INTERLACE_LINE = 'line'; |
---|
14 | const INTERLACE_PLANE = 'plane'; |
---|
15 | const INTERLACE_PARTITION = 'partition'; |
---|
16 | const INTERLACE_GIF = 'GIF'; |
---|
17 | const INTERLACE_JPEG = 'JPEG'; |
---|
18 | const INTERLACE_PNG = 'PNG'; |
---|
19 | |
---|
20 | const FILTER_POINT = 'Point'; |
---|
21 | const FILTER_BOX = 'Box'; |
---|
22 | const FILTER_TRIANGLE = 'Triangle'; |
---|
23 | const FILTER_HERMITE = 'Hermite'; |
---|
24 | const FILTER_HANNING = 'Hanning'; |
---|
25 | const FILTER_HAMMING = 'Hamming'; |
---|
26 | const FILTER_BLACKMAN = 'Blackman'; |
---|
27 | const FILTER_GAUSSIAN = 'Gaussian'; |
---|
28 | const FILTER_QUADRATIC = 'Quadratic'; |
---|
29 | const FILTER_CUBIC = 'Cubic'; |
---|
30 | const FILTER_CATROM = 'Catrom'; |
---|
31 | const FILTER_MITCHELL = 'Mitchell'; |
---|
32 | const FILTER_LANCZOS = 'Lanczos'; |
---|
33 | const FILTER_BESSEL = 'Bessel'; |
---|
34 | const FILTER_SINC = 'Sinc'; |
---|
35 | |
---|
36 | const ORIENTATION_TOPLEFT = 'top-left'; |
---|
37 | const ORIENTATION_TOPRIGHT = 'top-right'; |
---|
38 | const ORIENTATION_BOTTOMRIGHT = 'bottom-right'; |
---|
39 | const ORIENTATION_BOTTOMLEFT = 'bottom-left'; |
---|
40 | const ORIENTATION_LEFTTOP = 'left-top'; |
---|
41 | const ORIENTATION_RIGHTTOP = 'right-top'; |
---|
42 | const ORIENTATION_RIGHTBOTTOM = 'right-bottom'; |
---|
43 | const ORIENTATION_LEFTBOTTOM = 'left-bottom'; |
---|
44 | |
---|
45 | function __construct($source) |
---|
46 | { |
---|
47 | global $conf; |
---|
48 | |
---|
49 | $this->source_path = $source; |
---|
50 | |
---|
51 | if (isset($conf['imagick_dir'])) |
---|
52 | $this->imagemagickdir = rtrim($conf['imagick_dir'], ' /\\').'/'; |
---|
53 | |
---|
54 | $command = $this->imagemagickdir.'identify -format "%wx%h" "'.realpath($this->source_path).'"'; |
---|
55 | @exec($command, $returnarray, $returnvalue); |
---|
56 | if($returnvalue or !preg_match('/^(\d+)x(\d+)$/', $returnarray[0], $match)) |
---|
57 | { |
---|
58 | die("[External ImageMagick] Corrupt image"); |
---|
59 | } |
---|
60 | |
---|
61 | $this->width = $match[1]; |
---|
62 | $this->height = $match[2]; |
---|
63 | } |
---|
64 | |
---|
65 | function add_command($command, $params=null) |
---|
66 | { |
---|
67 | $this->commands[$command] = $params; |
---|
68 | } |
---|
69 | |
---|
70 | function getImageWidth() |
---|
71 | { |
---|
72 | return $this->width; |
---|
73 | } |
---|
74 | |
---|
75 | function getImageHeight() |
---|
76 | { |
---|
77 | return $this->height; |
---|
78 | } |
---|
79 | |
---|
80 | function setImageCompressionQuality($quality) |
---|
81 | { |
---|
82 | $this->add_command('quality', $quality); |
---|
83 | } |
---|
84 | |
---|
85 | function setInterlaceScheme($interlace) |
---|
86 | { |
---|
87 | $this->add_command('interlace', $interlace); |
---|
88 | } |
---|
89 | |
---|
90 | function resizeImage($width, $height, $filter, $blur) |
---|
91 | { |
---|
92 | $this->add_command('resize', $width.'x'.$height.'!'); |
---|
93 | $this->add_command('filter', $filter); |
---|
94 | //$this->add_command('blur', $blur); |
---|
95 | } |
---|
96 | |
---|
97 | function stripImage() |
---|
98 | { |
---|
99 | $this->add_command('strip'); |
---|
100 | } |
---|
101 | |
---|
102 | function rotateImage($background, $rotate) |
---|
103 | { |
---|
104 | $this->add_command('rotate', $rotate); |
---|
105 | } |
---|
106 | |
---|
107 | function setImageOrientation($orientation) |
---|
108 | { |
---|
109 | $this->add_command('orient', $orientation); |
---|
110 | } |
---|
111 | |
---|
112 | function cropImage($width, $height, $x, $y) |
---|
113 | { |
---|
114 | $this->add_command('crop', $width.'x'.$height.'+'.$x.'+'.$y); |
---|
115 | } |
---|
116 | |
---|
117 | function writeImage($destination_filepath) |
---|
118 | { |
---|
119 | global $conf; |
---|
120 | |
---|
121 | $exec = $this->imagemagickdir.'convert'; |
---|
122 | $exec .= ' "'.realpath($this->source_path).'"'; |
---|
123 | |
---|
124 | foreach ($this->commands as $command => $params) |
---|
125 | { |
---|
126 | $exec .= ' -'.$command; |
---|
127 | if (!empty($params)) |
---|
128 | { |
---|
129 | $exec .= ' '.$params; |
---|
130 | } |
---|
131 | } |
---|
132 | |
---|
133 | $dest = pathinfo($destination_filepath); |
---|
134 | $exec .= ' "'.realpath($dest['dirname']).'/'.$dest['basename'].'"'; |
---|
135 | @exec($exec, $returnarray, $returnvalue); |
---|
136 | } |
---|
137 | |
---|
138 | function destroy() |
---|
139 | { |
---|
140 | @unlink($this->tmp_path); |
---|
141 | return true; |
---|
142 | } |
---|
143 | } |
---|
144 | |
---|
145 | class ImagickPixel { } |
---|
146 | |
---|
147 | ?> |
---|