ImageMagick support (including SVG, etc.)

This commit is contained in:
Savetheinternet 2011-07-22 19:40:57 +10:00
parent f9bcde6e3d
commit ab0d6e27d7
2 changed files with 59 additions and 6 deletions

View File

@ -200,6 +200,9 @@
// Thumbnail extension, empty for inherited (png recommended) // Thumbnail extension, empty for inherited (png recommended)
$config['thumb_ext'] = 'png'; $config['thumb_ext'] = 'png';
// Use Imagick instead of GD (some further config options below are ignored if set)
$config['imagick'] = false;
// Thumbnail quality (compression level), from 0 to 9 // Thumbnail quality (compression level), from 0 to 9
$config['thumb_quality'] = 7; $config['thumb_quality'] = 7;
@ -609,6 +612,7 @@
// Allowed image file extensions // Allowed image file extensions
$config['allowed_ext'] = Array('jpg', 'jpeg', 'bmp', 'gif', 'png'); $config['allowed_ext'] = Array('jpg', 'jpeg', 'bmp', 'gif', 'png');
// $config['allowed_ext'][] = 'svg';
// Allowed additional file extensions (not images; downloadable files) // Allowed additional file extensions (not images; downloadable files)
$config['allowed_ext_files'] = Array(); $config['allowed_ext_files'] = Array();

View File

@ -13,10 +13,14 @@
$this->src = $src; $this->src = $src;
$this->format = $format; $this->format = $format;
if($config['imagick']) {
$classname = 'ImageImagick';
} else {
$classname = 'Image' . strtoupper($this->format); $classname = 'Image' . strtoupper($this->format);
if(!class_exists($classname)) { if(!class_exists($classname)) {
error('Unsupported file format: ' . $this->format); error('Unsupported file format: ' . $this->format);
} }
}
$this->image = new $classname($this); $this->image = new $classname($this);
if(!$this->image->valid()) { if(!$this->image->valid()) {
@ -32,10 +36,17 @@
} }
public function resize($extension, $max_width, $max_height) { public function resize($extension, $max_width, $max_height) {
global $config;
if($config['imagick']) {
$classname = 'ImageImagick';
} else {
$classname = 'Image' . strtoupper($extension); $classname = 'Image' . strtoupper($extension);
if(!class_exists($classname)) { if(!class_exists($classname)) {
error('Unsupported file format: ' . $extension); error('Unsupported file format: ' . $extension);
} }
}
$thumb = new $classname(false); $thumb = new $classname(false);
$thumb->original_width = $this->size->width; $thumb->original_width = $this->size->width;
$thumb->original_height = $this->size->height; $thumb->original_height = $this->size->height;
@ -86,6 +97,9 @@
} }
public function __construct($img) { public function __construct($img) {
if(method_exists($this, 'init'))
$this->init();
if($img !== false) { if($img !== false) {
$this->src = &$img->src; $this->src = &$img->src;
$this->from(); $this->from();
@ -123,6 +137,31 @@
} }
} }
class ImageImagick extends ImageBase {
public function init() {
$this->image = new Imagick();
}
public function from() {
$this->image->readImage($this->src);
}
public function to($src) {
$this->image->writeImage($src);
}
public function width() {
return $this->image->getImageWidth();
}
public function height() {
return $this->image->getImageHeight();
}
public function destroy() {
return $this->image->destroy();
}
public function resize() {
$this->image = $this->original;
$this->image->scaleImage($this->width, $this->height, false);
}
}
class ImagePNG extends ImageBase { class ImagePNG extends ImageBase {
public function from() { public function from() {
@ -176,6 +215,16 @@
} }
} }
class ImageSVG extends ImageBase {
public function from() {
$im = new Imagick();
$this->image = @imagecreatefrombmp($this->src);
}
public function to($src) {
imagebmp($this->image, $src);
}
}
/*********************************************/ /*********************************************/
/* Fonction: imagecreatefrombmp */ /* Fonction: imagecreatefrombmp */