Add ImageMagic support to thumbnail process
This commit is contained in:
parent
9b41846002
commit
5c0f55681c
|
@ -48,6 +48,10 @@ Installing
|
||||||
- Set ``TINYIB_REQMOD`` to ``all`` to require moderation for all posts.
|
- Set ``TINYIB_REQMOD`` to ``all`` to require moderation for all posts.
|
||||||
- Moderate posts by visiting the management panel.
|
- Moderate posts by visiting the management panel.
|
||||||
- When setting ``TINYIB_DBMODE`` to ``pdo``, note that PDO mode has been tested on **MySQL databases only**. Theoretically it will work with any applicable driver, but this is not guaranteed. If you use an alternative driver, please report back regarding how it works.
|
- When setting ``TINYIB_DBMODE`` to ``pdo``, note that PDO mode has been tested on **MySQL databases only**. Theoretically it will work with any applicable driver, but this is not guaranteed. If you use an alternative driver, please report back regarding how it works.
|
||||||
|
- To use ImageMagick instead of GD when creating thumbnails:
|
||||||
|
- Install ImageMagick and ensure that the ``convert`` command is available.
|
||||||
|
- Set ``TINYIB_THUMBNAIL`` to ``imagemagick``.
|
||||||
|
- **Note:** GIF files will have animated thumbnails, which will often have large file sizes.
|
||||||
6. [CHMOD](http://en.wikipedia.org/wiki/Chmod) write permissions to these directories:
|
6. [CHMOD](http://en.wikipedia.org/wiki/Chmod) write permissions to these directories:
|
||||||
- ./ (the directory containing TinyIB)
|
- ./ (the directory containing TinyIB)
|
||||||
- ./src/
|
- ./src/
|
||||||
|
|
|
@ -27,6 +27,9 @@ if (!defined('TINYIB_SWF')) {
|
||||||
if (!defined('TINYIB_WEBM')) {
|
if (!defined('TINYIB_WEBM')) {
|
||||||
define('TINYIB_WEBM', false);
|
define('TINYIB_WEBM', false);
|
||||||
}
|
}
|
||||||
|
if (!defined('TINYIB_THUMBNAIL')) {
|
||||||
|
define('TINYIB_THUMBNAIL', 'gd');
|
||||||
|
}
|
||||||
if (!defined('TINYIB_NOFILEOK')) {
|
if (!defined('TINYIB_NOFILEOK')) {
|
||||||
define('TINYIB_NOFILEOK', false);
|
define('TINYIB_NOFILEOK', false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -361,59 +361,70 @@ function thumbnailDimensions($post) {
|
||||||
return ($post['image_width'] > $max_width || $post['image_height'] > $max_height) ? array($max_width, $max_height) : array($post['image_width'], $post['image_height']);
|
return ($post['image_width'] > $max_width || $post['image_height'] > $max_height) ? array($max_width, $max_height) : array($post['image_width'], $post['image_height']);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createThumbnail($name, $filename, $new_w, $new_h) {
|
function createThumbnail($file_location, $thumb_location, $new_w, $new_h) {
|
||||||
$system = explode(".", $filename);
|
if (TINYIB_THUMBNAIL == 'gd') {
|
||||||
$system = array_reverse($system);
|
$system = explode(".", $thumb_location);
|
||||||
if (preg_match("/jpg|jpeg/", $system[0])) {
|
$system = array_reverse($system);
|
||||||
$src_img = imagecreatefromjpeg($name);
|
if (preg_match("/jpg|jpeg/", $system[0])) {
|
||||||
} else if (preg_match("/png/", $system[0])) {
|
$src_img = imagecreatefromjpeg($file_location);
|
||||||
$src_img = imagecreatefrompng($name);
|
} else if (preg_match("/png/", $system[0])) {
|
||||||
} else if (preg_match("/gif/", $system[0])) {
|
$src_img = imagecreatefrompng($file_location);
|
||||||
$src_img = imagecreatefromgif($name);
|
} else if (preg_match("/gif/", $system[0])) {
|
||||||
} else {
|
$src_img = imagecreatefromgif($file_location);
|
||||||
return false;
|
} else {
|
||||||
}
|
|
||||||
|
|
||||||
if (!$src_img) {
|
|
||||||
fancyDie("Unable to read uploaded file during thumbnailing. A common cause for this is an incorrect extension when the file is actually of a different type.");
|
|
||||||
}
|
|
||||||
$old_x = imageSX($src_img);
|
|
||||||
$old_y = imageSY($src_img);
|
|
||||||
$percent = ($old_x > $old_y) ? ($new_w / $old_x) : ($new_h / $old_y);
|
|
||||||
$thumb_w = round($old_x * $percent);
|
|
||||||
$thumb_h = round($old_y * $percent);
|
|
||||||
|
|
||||||
$dst_img = imagecreatetruecolor($thumb_w, $thumb_h);
|
|
||||||
if (preg_match("/png/", $system[0]) && imagepng($src_img, $filename)) {
|
|
||||||
imagealphablending($dst_img, false);
|
|
||||||
imagesavealpha($dst_img, true);
|
|
||||||
|
|
||||||
$color = imagecolorallocatealpha($dst_img, 0, 0, 0, 0);
|
|
||||||
imagefilledrectangle($dst_img, 0, 0, $thumb_w, $thumb_h, $color);
|
|
||||||
imagecolortransparent($dst_img, $color);
|
|
||||||
|
|
||||||
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
|
|
||||||
} else {
|
|
||||||
fastimagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (preg_match("/png/", $system[0])) {
|
|
||||||
if (!imagepng($dst_img, $filename)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (preg_match("/jpg|jpeg/", $system[0])) {
|
|
||||||
if (!imagejpeg($dst_img, $filename, 70)) {
|
if (!$src_img) {
|
||||||
return false;
|
fancyDie("Unable to read uploaded file during thumbnailing. A common cause for this is an incorrect extension when the file is actually of a different type.");
|
||||||
}
|
}
|
||||||
} else if (preg_match("/gif/", $system[0])) {
|
|
||||||
if (!imagegif($dst_img, $filename)) {
|
$old_x = imageSX($src_img);
|
||||||
|
$old_y = imageSY($src_img);
|
||||||
|
$percent = ($old_x > $old_y) ? ($new_w / $old_x) : ($new_h / $old_y);
|
||||||
|
$thumb_w = round($old_x * $percent);
|
||||||
|
$thumb_h = round($old_y * $percent);
|
||||||
|
|
||||||
|
$dst_img = imagecreatetruecolor($thumb_w, $thumb_h);
|
||||||
|
if (preg_match("/png/", $system[0]) && imagepng($src_img, $thumb_location)) {
|
||||||
|
imagealphablending($dst_img, false);
|
||||||
|
imagesavealpha($dst_img, true);
|
||||||
|
|
||||||
|
$color = imagecolorallocatealpha($dst_img, 0, 0, 0, 0);
|
||||||
|
imagefilledrectangle($dst_img, 0, 0, $thumb_w, $thumb_h, $color);
|
||||||
|
imagecolortransparent($dst_img, $color);
|
||||||
|
|
||||||
|
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
|
||||||
|
} else {
|
||||||
|
fastimagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (preg_match("/png/", $system[0])) {
|
||||||
|
if (!imagepng($dst_img, $thumb_location)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (preg_match("/jpg|jpeg/", $system[0])) {
|
||||||
|
if (!imagejpeg($dst_img, $thumb_location, 70)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (preg_match("/gif/", $system[0])) {
|
||||||
|
if (!imagegif($dst_img, $thumb_location)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
imagedestroy($dst_img);
|
||||||
|
imagedestroy($src_img);
|
||||||
|
} else { // imagemagick
|
||||||
|
$discard = '';
|
||||||
|
$exit_status = 1;
|
||||||
|
exec("convert $file_location -auto-orient -thumbnail '" . $new_w . "x" . $new_h . "' -coalesce -layers OptimizeFrame -depth 4 -type palettealpha $thumb_location", $discard, $exit_status);
|
||||||
|
|
||||||
|
if ($exit_status != 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
imagedestroy($dst_img);
|
|
||||||
imagedestroy($src_img);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ define('TINYIB_WEBM', false); // Enable .weba and .webm audio/video file
|
||||||
// File control
|
// File control
|
||||||
define('TINYIB_MAXKB', 2048); // Maximum file size in kilobytes [0 to disable]
|
define('TINYIB_MAXKB', 2048); // Maximum file size in kilobytes [0 to disable]
|
||||||
define('TINYIB_MAXKBDESC', "2 MB"); // Human-readable representation of the maximum file size
|
define('TINYIB_MAXKBDESC', "2 MB"); // Human-readable representation of the maximum file size
|
||||||
|
define('TINYIB_THUMBNAIL', 'gd'); // Thumbnail method to use: gd / imagemagick (see README for instructions)
|
||||||
define('TINYIB_NOFILEOK', false); // Allow the creation of new threads without uploading a file
|
define('TINYIB_NOFILEOK', false); // Allow the creation of new threads without uploading a file
|
||||||
|
|
||||||
// Thumbnail size - new thread
|
// Thumbnail size - new thread
|
||||||
|
|
Loading…
Reference in New Issue
Block a user