Added thumb_scaling option for generating high-dpi thumbnails

This commit is contained in:
Matthew Barbour 2019-06-05 20:09:03 -05:00
parent 8612a07a5a
commit 49cb6f7233
6 changed files with 22 additions and 23 deletions

View file

@ -57,6 +57,7 @@ class ET extends Extension
$info['thumb_quality'] = $config->get_int('thumb_quality');
$info['thumb_width'] = $config->get_int('thumb_width');
$info['thumb_height'] = $config->get_int('thumb_height');
$info['thumb_scaling'] = $config->get_int('thumb_scaling');
$info['thumb_mem'] = $config->get_int("thumb_mem_limit");
$info['stat_images'] = $database->get_one("SELECT COUNT(*) FROM images");

View file

@ -41,6 +41,7 @@ Memory: {$info['thumb_mem']}
Quality: {$info['thumb_quality']}
Width: {$info['thumb_width']}
Height: {$info['thumb_height']}
Scaling: {$info['thumb_scaling']}
Shimmie stats:
Images: {$info['stat_images']}

View file

@ -88,8 +88,10 @@ class IcoFileHandler extends Extension
$inname = warehouse_path("images", $hash);
$outname = warehouse_path("thumbs", $hash);
$w = $config->get_int("thumb_width");
$h = $config->get_int("thumb_height");
$tsize = get_thumbnail_size_scaled($width, $height);
$w = $tsize[0];
$h = $tsise[1];
$q = $config->get_int("thumb_quality");
$mem = $config->get_int("thumb_mem_limit") / 1024 / 1024; // IM takes memory in MB

View file

@ -103,8 +103,6 @@ class PixelFileHandler extends DataHandlerExtension
{
global $config;
$w = $config->get_int("thumb_width");
$h = $config->get_int("thumb_height");
$q = $config->get_int("thumb_quality");
$convert = $config->get_string("thumb_convert_path");
@ -114,12 +112,10 @@ class PixelFileHandler extends DataHandlerExtension
//$size = shell_exec($cmd);
//$size = explode(" ", trim($size));
$size = getimagesize($inname);
if ($size[0] > $size[1]*5) {
$size[0] = $size[1]*5;
}
if ($size[1] > $size[0]*5) {
$size[1] = $size[0]*5;
}
$tsize = get_thumbnail_size_scaled($size[0] , $size[1]);
$w = $tsize[0];
$h = $tsize[1];
// running the call with cmd.exe requires quoting for our paths
$format = '"%s" "%s[0]" -extent %ux%u -flatten -strip -thumbnail %ux%u -quality %u jpg:"%s"';
@ -158,24 +154,18 @@ class PixelFileHandler extends DataHandlerExtension
$memory_limit = get_memory_limit();
if ($memory_use > $memory_limit) {
$w = $config->get_int('thumb_width');
$h = $config->get_int('thumb_height');
$thumb = imagecreatetruecolor($w, min($h, 64));
$tsize = get_thumbnail_size_scaled($width, $height);
$w = $tsize[0];
$h = $tsize[1];
$thumb = imagecreatetruecolor($w, min($h, 64));
$white = imagecolorallocate($thumb, 255, 255, 255);
$black = imagecolorallocate($thumb, 0, 0, 0);
imagefill($thumb, 0, 0, $white);
imagestring($thumb, 5, 10, 24, "Image Too Large :(", $black);
return $thumb;
} else {
if ($width > $height*5) {
$width = $height*5;
}
if ($height > $width*5) {
$height = $width*5;
}
$image = imagecreatefromstring(file_get_contents($tmpname));
$tsize = get_thumbnail_size($width, $height);
$tsize = get_thumbnail_size_scaled($width, $height);
$thumb = imagecreatetruecolor($tsize[0], $tsize[1]);
imagecopyresampled(

View file

@ -64,7 +64,7 @@ class VideoFileHandler extends DataHandlerExtension
$outname = warehouse_path("thumbs", $hash);
$orig_size = $this->video_size($inname);
$scaled_size = get_thumbnail_size($orig_size[0], $orig_size[1]);
$scaled_size = get_thumbnail_size_scaled($orig_size[0], $orig_size[1]);
$cmd = escapeshellcmd(implode(" ", [
escapeshellarg($ffmpeg),
"-y", "-i", escapeshellarg($inname),

View file

@ -19,6 +19,7 @@ class ImageIO extends Extension
global $config;
$config->set_default_int('thumb_width', 192);
$config->set_default_int('thumb_height', 192);
$config->set_default_int('thumb_scaling', 100);
$config->set_default_int('thumb_quality', 75);
$config->set_default_int('thumb_mem_limit', parse_shorthand_int('8MB'));
$config->set_default_string('thumb_convert_path', 'convert');
@ -147,7 +148,11 @@ class ImageIO extends Extension
$sb->add_label(" px at ");
$sb->add_int_option("thumb_quality");
$sb->add_label(" % quality ");
$sb->add_label("<br>High-DPI scaling ");
$sb->add_int_option("thumb_scaling");
$sb->add_label("%");
if ($config->get_string("thumb_engine") == "convert") {
$sb->add_label("<br>ImageMagick Binary: ");
$sb->add_text_option("thumb_convert_path");