summaryrefslogtreecommitdiff
path: root/inc/image.php
diff options
context:
space:
mode:
authorMichael Save <savetheinternet@tinyboard.org>2012-03-17 10:32:50 +1100
committerMichael Save <savetheinternet@tinyboard.org>2012-03-17 10:32:50 +1100
commit4c3486bec95312553a699f7681916cbd4b0b8c50 (patch)
tree1f870c18302426bf7b24db5c7ce7d9ad21e9655f /inc/image.php
parentd531487bad5524f4a7c3d6e0c35b1293cb7924d2 (diff)
Thumbnailing alternative: `convert` (command line ImageMagick instead of PHP bindings)
Diffstat (limited to 'inc/image.php')
-rw-r--r--inc/image.php46
1 files changed, 43 insertions, 3 deletions
diff --git a/inc/image.php b/inc/image.php
index 85200104..45a7df18 100644
--- a/inc/image.php
+++ b/inc/image.php
@@ -14,7 +14,7 @@
$this->format = $format;
if($config['imagick']) {
- $classname = 'ImageImagick';
+ $classname = $config['imagick_convert'] ? 'ImageConvert' : 'ImageImagick';
} else {
$classname = 'Image' . strtoupper($this->format);
if(!class_exists($classname)) {
@@ -39,7 +39,7 @@
global $config;
if($config['imagick']) {
- $classname = 'ImageImagick';
+ $classname = $config['imagick_convert'] ? 'ImageConvert' : 'ImageImagick';
} else {
$classname = 'Image' . strtoupper($extension);
if(!class_exists($classname)) {
@@ -200,13 +200,53 @@
}
} else {
$this->image = clone $this->original;
- // only resize one frame
$this->image->scaleImage($this->width, $this->height, false);
}
}
}
+ class ImageConvert extends ImageBase {
+ public $width, $height, $temp;
+
+ public function init() {
+ global $config;
+
+ $this->temp = tempnam($config['tmp'], 'imagick');
+
+ }
+ public function from() {
+ if(!$size = @getimagesize($this->src))
+ return $this->image = false;
+
+ $this->width = $size[0];
+ $this->height = $size[1];
+
+ // mark as valid
+ $this->image = true;
+ }
+ public function to($src) {
+ rename($this->temp, $src);
+ }
+ public function width() {
+ return $this->width;
+ }
+ public function height() {
+ return $this->height;
+ }
+ public function destroy() {
+ unlink($this->temp);
+ }
+ public function resize() {
+ global $config;
+
+ $quality = $config['thumb_quality'] * 10;
+
+ if(shell_exec("convert -flatten -filter Point -resize {$this->width}x{$this->height} -quality {$quality} " . escapeshellarg($this->src) . " " . escapeshellarg($this->temp)))
+ error('Failed to resize image!');
+ }
+ }
+
class ImagePNG extends ImageBase {
public function from() {
$this->image = @imagecreatefrompng($this->src);