Change imagemagick commands to return the error output

Added ico to transcode extension
This commit is contained in:
Matthew Barbour 2019-06-14 12:59:12 -05:00 committed by matthew
parent 070429402b
commit 58acb71282
2 changed files with 16 additions and 5 deletions

View file

@ -208,8 +208,11 @@ function create_thumbnail_convert($hash, $input_type = ""): bool
$cmd = sprintf($format, $convert, $w, $h, $options, $q, $bg,$input_type, $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);
log_debug('handle_pixel', "Generating thumbnail with command `$cmd`, returns $ret");
if ($ret!=0) {
log_warning('imageboard/misc', "Generating thumbnail with command `$cmd`, returns $ret, outputting ".implode("\r\n",$output));
} else {
log_debug('imageboard/misc', "Generating thumbnail with command `$cmd`, returns $ret");
}
if ($config->get_bool("thumb_optim", false)) {
exec("jpegoptim $outname", $output, $ret);

View file

@ -43,6 +43,7 @@ class TranscodeImage extends Extension
"psd",
"tiff",
"webp",
"ico",
]
];
@ -68,6 +69,7 @@ class TranscodeImage extends Extension
const INPUT_FORMATS = [
"BMP" => "bmp",
"GIF" => "gif",
"ICO" => "ico",
"JPG" => "jpg",
"PNG" => "png",
"PSD" => "psd",
@ -440,15 +442,21 @@ class TranscodeImage extends Extension
}
$tmp_name = tempnam("/tmp", "shimmie_transcode");
$format = '"%s" %s -quality %u -background %s "%s" %s:"%s"';
$cmd = sprintf($format, $convert, $args, $q, $bg, $source_name, $ext, $tmp_name);
$source_type = "";
switch ($source_format) {
case "ico":
$source_type = "ico:";
}
$format = '"%s" %s -quality %u -background %s %s"%s" %s:"%s" 2>&1';
$cmd = sprintf($format, $convert, $args, $q, $bg, $source_type, $source_name, $ext, $tmp_name);
$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);
log_debug('transcode', "Transcoding with command `$cmd`, returns $ret");
if ($ret!==0) {
throw new ImageTranscodeException("Transcoding failed with command ".$cmd);
throw new ImageTranscodeException("Transcoding failed with command ".$cmd.", returning ".implode("\r\n", $output));
}
return $tmp_name;