From 1aa0225652130aa590ef4345c6356707a43b2156 Mon Sep 17 00:00:00 2001 From: Matthew Barbour Date: Thu, 13 Jun 2019 11:45:34 -0500 Subject: [PATCH] Adjustments to transcoding to allow psd transcoding to actually work Changed resize extension to run later in the extension stack Little fixes --- core/imageboard/misc.php | 9 +++++---- core/polyfills.php | 3 ++- ext/resize/main.php | 9 +++++++++ ext/transcode/main.php | 14 +++++++------- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/core/imageboard/misc.php b/core/imageboard/misc.php index f260efa6..eb3c4146 100644 --- a/core/imageboard/misc.php +++ b/core/imageboard/misc.php @@ -201,12 +201,13 @@ function create_thumbnail_convert($hash): bool $options .= "\>"; } + $bg = "black"; if($type=="webp") { - $format = '"%s" -thumbnail %ux%u%s -quality %u -background none "%s[0]" %s:"%s"'; - } else { - $format = '"%s" -flatten -strip -thumbnail %ux%u%s -quality %u "%s[0]" %s:"%s"'; + $bg = "none"; } - $cmd = sprintf($format, $convert, $w, $h, $options, $q, $inname, $type, $outname); + $format = '"%s" -flatten -strip -thumbnail %ux%u%s -quality %u -background %s "%s[0]" %s:"%s"'; + + $cmd = sprintf($format, $convert, $w, $h, $options, $q, $bg, $inname, $type, $outname); $cmd = str_replace("\"convert\"", "convert", $cmd); // quotes are only needed if the path to convert contains a space; some other times, quotes break things, see github bug #27 exec($cmd, $output, $ret); diff --git a/core/polyfills.php b/core/polyfills.php index 4b07aac7..97b1e1ec 100644 --- a/core/polyfills.php +++ b/core/polyfills.php @@ -265,7 +265,8 @@ const MIME_TYPE_MAP = [ 'avi' => 'video/x-msvideo', 'mpg' => 'video/mpeg', 'mpeg' => 'video/mpeg', 'mov' => 'video/quicktime', 'flv' => 'video/x-flv', 'php' => 'text/x-php', 'mp4' => 'video/mp4', 'ogv' => 'video/ogg', 'webm' => 'video/webm', - 'webp' => 'image/webp', 'bmp' =>'image/x-ms-bmp' + 'webp' => 'image/webp', 'bmp' =>'image/x-ms-bmp', 'psd' => 'image/vnd.adobe.photoshop', + 'mkv' => 'video/x-matroska' ]; /** diff --git a/ext/resize/main.php b/ext/resize/main.php index ac90aac6..41eabde0 100644 --- a/ext/resize/main.php +++ b/ext/resize/main.php @@ -16,6 +16,15 @@ */ class ResizeImage extends Extension { + /** + * Needs to be after the data processing extensions + */ + public function get_priority(): int + { + return 55; + } + + public function onInitExt(InitExtEvent $event) { global $config; diff --git a/ext/transcode/main.php b/ext/transcode/main.php index f71ce76a..9e63233e 100644 --- a/ext/transcode/main.php +++ b/ext/transcode/main.php @@ -87,7 +87,7 @@ class TranscodeImage extends Extension ]; /** - * Need to be after upload, but before the processing extensions + * Needs to be after upload, but before the processing extensions */ public function get_priority(): int { @@ -238,7 +238,7 @@ class TranscodeImage extends Extension if($image==null) { continue; } - + $this->transcode_and_replace_image($image, $format); // If a subsequent transcode fails, the database need to have everything about the previous transcodes recorded already, // otherwise the image entries will be stuck pointing to missing image files @@ -424,20 +424,20 @@ class TranscodeImage extends Extension } $ext = $this->determine_ext($target_format); - $args = "-flatten"; + $args = " -flatten "; $bg = "none"; switch($target_format) { case "webp-lossless": - $args = '-define webp:lossless=true'; + $args .= '-define webp:lossless=true'; break; case "webp-lossy": - $args = ''; + $args .= ''; break; case "png": - $args = '-define png:compression-level=9'; + $args .= '-define png:compression-level=9'; break; default: - $bg = "white"; + $bg = "black"; break; } $tmp_name = tempnam("/tmp", "shimmie_transcode");