[9852] | 1 | <?php |
---|
| 2 | |
---|
| 3 | class Imagick |
---|
| 4 | { |
---|
[9856] | 5 | var $source_path = ''; |
---|
| 6 | var $image_data = array(); |
---|
| 7 | var $imagemagickdir = ''; |
---|
| 8 | var $commands = array(); |
---|
[11650] | 9 | var $width = ''; |
---|
| 10 | var $height = ''; |
---|
[9852] | 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'])) |
---|
[9860] | 52 | $this->imagemagickdir = rtrim($conf['imagick_dir'], ' /\\').'/'; |
---|
[9852] | 53 | |
---|
[11650] | 54 | $command = $this->imagemagickdir.'identify -format "%wx%h" "'.realpath($this->source_path).'"'; |
---|
[9852] | 55 | @exec($command, $returnarray, $returnvalue); |
---|
[11650] | 56 | if($returnvalue or !preg_match('/^(\d+)x(\d+)$/', $returnarray[0], $match)) |
---|
[9852] | 57 | { |
---|
[11650] | 58 | die("[External ImageMagick] Corrupt image"); |
---|
[9852] | 59 | } |
---|
[11650] | 60 | |
---|
| 61 | $this->width = $match[1]; |
---|
| 62 | $this->height = $match[2]; |
---|
[9852] | 63 | } |
---|
| 64 | |
---|
| 65 | function add_command($command, $params=null) |
---|
| 66 | { |
---|
| 67 | $this->commands[$command] = $params; |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | function getImageWidth() |
---|
| 71 | { |
---|
[11650] | 72 | return $this->width; |
---|
[9852] | 73 | } |
---|
| 74 | |
---|
| 75 | function getImageHeight() |
---|
| 76 | { |
---|
[11650] | 77 | return $this->height; |
---|
[9852] | 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'; |
---|
[11650] | 122 | $exec .= ' "'.realpath($this->source_path).'"'; |
---|
[9852] | 123 | |
---|
| 124 | foreach ($this->commands as $command => $params) |
---|
| 125 | { |
---|
| 126 | $exec .= ' -'.$command; |
---|
| 127 | if (!empty($params)) |
---|
| 128 | { |
---|
| 129 | $exec .= ' '.$params; |
---|
| 130 | } |
---|
| 131 | } |
---|
| 132 | |
---|
[9860] | 133 | $dest = pathinfo($destination_filepath); |
---|
[11650] | 134 | $exec .= ' "'.realpath($dest['dirname']).'/'.$dest['basename'].'"'; |
---|
[9852] | 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 | ?> |
---|