summaryrefslogtreecommitdiff
path: root/inc/image.php
diff options
context:
space:
mode:
authorMarcin Ɓabanowski <marcin@6irc.net>2012-12-24 05:34:06 +0100
committerMichael Foster <savetheinternet@tinyboard.org>2013-07-31 03:33:06 -0400
commitb7e725bf3e0394193dee9373c18dec7f727ea6ed (patch)
tree0d17ef917f4c43bb5484edb5ea7aab1b193bc096 /inc/image.php
parentf9cdf31ede3bab1aff1ffa5a043bfd9a6eceb6d7 (diff)
Support for resizing gifs using gifsicle with resizing the rest using ImageMagick
Diffstat (limited to 'inc/image.php')
-rw-r--r--inc/image.php28
1 files changed, 22 insertions, 6 deletions
diff --git a/inc/image.php b/inc/image.php
index f0909b8c..e4738953 100644
--- a/inc/image.php
+++ b/inc/image.php
@@ -16,10 +16,10 @@ class Image {
$this->src = $src;
$this->format = $format;
-
+
if ($config['thumb_method'] == 'imagick') {
$classname = 'ImageImagick';
- } elseif ($config['thumb_method'] == 'convert') {
+ } elseif ($config['thumb_method'] == 'convert' || $config['thumb_method'] == 'convert+gifsicle') {
$classname = 'ImageConvert';
} else {
$classname = 'Image' . strtoupper($this->format);
@@ -29,6 +29,7 @@ class Image {
}
$this->image = new $classname($this);
+
if (!$this->image->valid()) {
$this->delete();
error($config['error']['invalidimg']);
@@ -44,10 +45,15 @@ class Image {
public function resize($extension, $max_width, $max_height) {
global $config;
+ $gifsicle = false;
+
if ($config['thumb_method'] == 'imagick') {
$classname = 'ImageImagick';
} elseif ($config['thumb_method'] == 'convert') {
$classname = 'ImageConvert';
+ } elseif ($config['thumb_method'] == 'convert+gifsicle') {
+ $classname = 'ImageConvert';
+ $gifsicle = true;
} else {
$classname = 'Image' . strtoupper($extension);
if (!class_exists($classname)) {
@@ -75,6 +81,9 @@ class Image {
$height = $max_height;
}
+ if ($gifsicle) {
+ $thumb->gifsicle = 1;
+ }
$thumb->_resize($this->image->image, $width, $height);
return $thumb;
@@ -219,7 +228,7 @@ class ImageImagick extends ImageBase {
class ImageConvert extends ImageBase {
- public $width, $height, $temp;
+ public $width, $height, $temp, $gifsicle;
public function init() {
global $config;
@@ -275,9 +284,16 @@ class ImageConvert extends ImageBase {
$quality = $config['thumb_quality'] * 10;
if ($this->format == 'gif' && ($config['thumb_ext'] == 'gif' || $config['thumb_ext'] == '') && $config['thumb_keep_animation_frames'] > 1) {
- if (shell_exec("convert -background transparent -filter Point -sample {$this->width}x{$this->height} +antialias -quality {$quality} " .
- escapeshellarg($this->src . '') . " " . escapeshellarg($this->temp)) || !file_exists($this->temp))
- error('Failed to resize image!');
+ if ($this->gifsicle) {
+ if (shell_exec("gifsicle --unoptimize -O2 --resize {$this->width}x{$this->height} " .
+ escapeshellarg($this->src . '') . " " . escapeshellarg($this->temp)) || !file_exists($this->temp))
+ error('Failed to resize image!');
+ }
+ else {
+ if (shell_exec("convert -background transparent -filter Point -sample {$this->width}x{$this->height} +antialias -quality {$quality} " .
+ escapeshellarg($this->src . '') . " " . escapeshellarg($this->temp)) || !file_exists($this->temp))
+ error('Failed to resize image!');
+ }
} else {
if (shell_exec("convert -background transparent -flatten -filter Point -scale {$this->width}x{$this->height} +antialias -quality {$quality} " .
escapeshellarg($this->src . '[0]') . " " . escapeshellarg($this->temp)) || !file_exists($this->temp))