Support for resizing gifs using gifsicle with resizing the rest using ImageMagick
This commit is contained in:
parent
c1a737d4b4
commit
5cea5ca16e
@ -408,11 +408,16 @@
|
|||||||
$config['thumb_keep_animation_frames'] = 1;
|
$config['thumb_keep_animation_frames'] = 1;
|
||||||
|
|
||||||
// Thumbnailing method:
|
// Thumbnailing method:
|
||||||
// - 'gd' PHP GD (default). Only handles the most basic image formats (GIF, JPEG, PNG). This is a prerequisite
|
// - 'gd' PHP GD (default). Only handles the most basic image formats (GIF, JPEG, PNG).
|
||||||
// for Tinyboard no matter what method you choose.
|
// This is a prerequisite for Tinyboard no matter what method you choose.
|
||||||
// - 'imagick' PHP's ImageMagick bindings. Fast and efficient, supporting many image formats. A few minor bugs.
|
// - 'imagick' PHP's ImageMagick bindings. Fast and efficient, supporting many image formats.
|
||||||
// http://pecl.php.net/package/imagick
|
// A few minor bugs. http://pecl.php.net/package/imagick
|
||||||
// - 'convert' The command line version of ImageMagick (`convert`). Fixes most of the bugs in PHP Imagick.
|
// - 'convert' The command line version of ImageMagick (`convert`). Fixes most of the bugs in
|
||||||
|
// PHP Imagick.
|
||||||
|
// - 'convert+gifsicle' Same as above, with the exception of using `gifsicle` (command line application)
|
||||||
|
// instead of `convert` for resizing gifs. It's faster and resulting animated gifs
|
||||||
|
// have less artifacts than if resized with ImageMagick.
|
||||||
|
|
||||||
$config['thumb_method'] = 'gd';
|
$config['thumb_method'] = 'gd';
|
||||||
|
|
||||||
// Regular expression to check for IE MIME type detection XSS exploit. To disable, comment the line out
|
// Regular expression to check for IE MIME type detection XSS exploit. To disable, comment the line out
|
||||||
|
@ -16,10 +16,10 @@ class Image {
|
|||||||
|
|
||||||
$this->src = $src;
|
$this->src = $src;
|
||||||
$this->format = $format;
|
$this->format = $format;
|
||||||
|
|
||||||
if ($config['thumb_method'] == 'imagick') {
|
if ($config['thumb_method'] == 'imagick') {
|
||||||
$classname = 'ImageImagick';
|
$classname = 'ImageImagick';
|
||||||
} elseif ($config['thumb_method'] == 'convert') {
|
} elseif ($config['thumb_method'] == 'convert' || $config['thumb_method'] == 'convert+gifsicle') {
|
||||||
$classname = 'ImageConvert';
|
$classname = 'ImageConvert';
|
||||||
} else {
|
} else {
|
||||||
$classname = 'Image' . strtoupper($this->format);
|
$classname = 'Image' . strtoupper($this->format);
|
||||||
@ -29,6 +29,7 @@ class Image {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->image = new $classname($this);
|
$this->image = new $classname($this);
|
||||||
|
|
||||||
if (!$this->image->valid()) {
|
if (!$this->image->valid()) {
|
||||||
$this->delete();
|
$this->delete();
|
||||||
error($config['error']['invalidimg']);
|
error($config['error']['invalidimg']);
|
||||||
@ -44,10 +45,15 @@ class Image {
|
|||||||
public function resize($extension, $max_width, $max_height) {
|
public function resize($extension, $max_width, $max_height) {
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
|
$gifsicle = false;
|
||||||
|
|
||||||
if ($config['thumb_method'] == 'imagick') {
|
if ($config['thumb_method'] == 'imagick') {
|
||||||
$classname = 'ImageImagick';
|
$classname = 'ImageImagick';
|
||||||
} elseif ($config['thumb_method'] == 'convert') {
|
} elseif ($config['thumb_method'] == 'convert') {
|
||||||
$classname = 'ImageConvert';
|
$classname = 'ImageConvert';
|
||||||
|
} elseif ($config['thumb_method'] == 'convert+gifsicle') {
|
||||||
|
$classname = 'ImageConvert';
|
||||||
|
$gifsicle = true;
|
||||||
} else {
|
} else {
|
||||||
$classname = 'Image' . strtoupper($extension);
|
$classname = 'Image' . strtoupper($extension);
|
||||||
if (!class_exists($classname)) {
|
if (!class_exists($classname)) {
|
||||||
@ -75,6 +81,9 @@ class Image {
|
|||||||
$height = $max_height;
|
$height = $max_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($gifsicle) {
|
||||||
|
$thumb->gifsicle = 1;
|
||||||
|
}
|
||||||
$thumb->_resize($this->image->image, $width, $height);
|
$thumb->_resize($this->image->image, $width, $height);
|
||||||
|
|
||||||
return $thumb;
|
return $thumb;
|
||||||
@ -216,7 +225,7 @@ class ImageImagick extends ImageBase {
|
|||||||
|
|
||||||
|
|
||||||
class ImageConvert extends ImageBase {
|
class ImageConvert extends ImageBase {
|
||||||
public $width, $height, $temp;
|
public $width, $height, $temp, $gifsicle;
|
||||||
|
|
||||||
public function init() {
|
public function init() {
|
||||||
global $config;
|
global $config;
|
||||||
@ -267,9 +276,16 @@ class ImageConvert extends ImageBase {
|
|||||||
$quality = $config['thumb_quality'] * 10;
|
$quality = $config['thumb_quality'] * 10;
|
||||||
|
|
||||||
if ($this->format == 'gif' && ($config['thumb_ext'] == 'gif' || $config['thumb_ext'] == '') && $config['thumb_keep_animation_frames'] > 1) {
|
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} " .
|
if ($this->gifsicle) {
|
||||||
escapeshellarg($this->src . '') . " " . escapeshellarg($this->temp)) || !file_exists($this->temp))
|
if (shell_exec("gifsicle --unoptimize -O2 --resize {$this->width}x{$this->height} " .
|
||||||
error('Failed to resize image!');
|
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 {
|
} else {
|
||||||
if (shell_exec("convert -background transparent -flatten -filter Point -scale {$this->width}x{$this->height} +antialias -quality {$quality} " .
|
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))
|
escapeshellarg($this->src . '[0]') . " " . escapeshellarg($this->temp)) || !file_exists($this->temp))
|
||||||
|
Loading…
Reference in New Issue
Block a user