Various fixes
This commit is contained in:
parent
ae6126d388
commit
a0c0b6e3d1
@ -178,6 +178,11 @@ function create_image_thumb(string $hash, string $type, string $engine = null) {
|
|||||||
$engine = $config->get_string(ImageConfig::THUMB_ENGINE);
|
$engine = $config->get_string(ImageConfig::THUMB_ENGINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$output_format = $config->get_string(ImageConfig::THUMB_TYPE);
|
||||||
|
if($output_format=="webp") {
|
||||||
|
$output_format = Media::WEBP_LOSSY;
|
||||||
|
}
|
||||||
|
|
||||||
send_event(new MediaResizeEvent(
|
send_event(new MediaResizeEvent(
|
||||||
$engine,
|
$engine,
|
||||||
$inname,
|
$inname,
|
||||||
@ -186,7 +191,7 @@ function create_image_thumb(string $hash, string $type, string $engine = null) {
|
|||||||
$tsize[0],
|
$tsize[0],
|
||||||
$tsize[1],
|
$tsize[1],
|
||||||
false,
|
false,
|
||||||
$config->get_string(ImageConfig::THUMB_TYPE),
|
$output_format,
|
||||||
$config->get_int(ImageConfig::THUMB_QUALITY),
|
$config->get_int(ImageConfig::THUMB_QUALITY),
|
||||||
true,
|
true,
|
||||||
$config->get_bool('thumb_upscale', false)
|
$config->get_bool('thumb_upscale', false)
|
||||||
|
@ -13,6 +13,15 @@ class VideoFileHandlerTheme extends Themelet
|
|||||||
$loop = $config->get_bool("video_playback_loop");
|
$loop = $config->get_bool("video_playback_loop");
|
||||||
$player = make_link('vendor/bower-asset/mediaelement/build/flashmediaelement.swf');
|
$player = make_link('vendor/bower-asset/mediaelement/build/flashmediaelement.swf');
|
||||||
|
|
||||||
|
$width="auto";
|
||||||
|
if($image->width>1) {
|
||||||
|
$width = $image->width."px";
|
||||||
|
}
|
||||||
|
$height="auto";
|
||||||
|
if($image->height>1) {
|
||||||
|
$height = $image->height."px";
|
||||||
|
}
|
||||||
|
|
||||||
$html = "Video not playing? <a href='$ilink'>Click here</a> to download the file.<br/>";
|
$html = "Video not playing? <a href='$ilink'>Click here</a> to download the file.<br/>";
|
||||||
|
|
||||||
//Browser media format support: https://developer.mozilla.org/en-US/docs/Web/HTML/Supported_media_formats
|
//Browser media format support: https://developer.mozilla.org/en-US/docs/Web/HTML/Supported_media_formats
|
||||||
@ -48,7 +57,8 @@ class VideoFileHandlerTheme extends Themelet
|
|||||||
$loop = ($loop ? ' loop' : '');
|
$loop = ($loop ? ' loop' : '');
|
||||||
|
|
||||||
$html .= "
|
$html .= "
|
||||||
<video controls class='shm-main-image' id='main_image' alt='main image' poster='$thumb_url' {$autoplay} {$loop} style='max-width: 100%'>
|
<video controls class='shm-main-image' id='main_image' alt='main image' poster='$thumb_url' {$autoplay} {$loop}
|
||||||
|
style='height: $height; width: $width; max-width: 100%'>
|
||||||
<source src='{$ilink}' type='{$supportedExts[$ext]}'>
|
<source src='{$ilink}' type='{$supportedExts[$ext]}'>
|
||||||
|
|
||||||
<!-- If browser doesn't support filetype, fallback to flash -->
|
<!-- If browser doesn't support filetype, fallback to flash -->
|
||||||
|
@ -726,6 +726,17 @@ class Media extends Extension
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
public static function is_lossless(string $filename, string $format) {
|
||||||
|
if(in_array($format, self::LOSSLESS_FORMATS)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch($format) {
|
||||||
|
case "webp":
|
||||||
|
return self::is_lossless_webp($filename);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public static function image_resize_convert(
|
public static function image_resize_convert(
|
||||||
String $input_path,
|
String $input_path,
|
||||||
@ -752,6 +763,10 @@ class Media extends Extension
|
|||||||
$output_type = $input_type;
|
$output_type = $input_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($output_type=="webp" && self::is_lossless($input_path, $input_type)) {
|
||||||
|
$output_type = self::WEBP_LOSSLESS;
|
||||||
|
}
|
||||||
|
|
||||||
$bg = "black";
|
$bg = "black";
|
||||||
if (self::supports_alpha($output_type)) {
|
if (self::supports_alpha($output_type)) {
|
||||||
$bg = "none";
|
$bg = "none";
|
||||||
@ -759,7 +774,8 @@ class Media extends Extension
|
|||||||
if (!empty($input_type)) {
|
if (!empty($input_type)) {
|
||||||
$input_type = $input_type . ":";
|
$input_type = $input_type . ":";
|
||||||
}
|
}
|
||||||
$args = "";
|
|
||||||
|
$args = " -flatten ";
|
||||||
if ($minimize) {
|
if ($minimize) {
|
||||||
$args = " -strip -thumbnail";
|
$args = " -strip -thumbnail";
|
||||||
}
|
}
|
||||||
@ -772,8 +788,19 @@ class Media extends Extension
|
|||||||
$resize_args .= "\!";
|
$resize_args .= "\!";
|
||||||
}
|
}
|
||||||
|
|
||||||
$format = '"%s" -flatten %s %ux%u%s -quality %u -background %s %s"%s[0]" %s:"%s" 2>&1';
|
switch ($output_type) {
|
||||||
$cmd = sprintf($format, $convert, $args, $new_width, $new_height, $resize_args, $output_quality, $bg, $input_type, $input_path, $output_type, $output_filename);
|
case Media::WEBP_LOSSLESS:
|
||||||
|
$args .= '-define webp:lossless=true';
|
||||||
|
break;
|
||||||
|
case "png":
|
||||||
|
$args .= '-define png:compression-level=9';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$output_ext = self::determine_ext($output_type);
|
||||||
|
|
||||||
|
$format = '"%s" %s -resize %ux%u%s -quality %u -background %s %s"%s[0]" %s:"%s" 2>&1';
|
||||||
|
$cmd = sprintf($format, $convert, $args, $new_width, $new_height, $resize_args, $output_quality, $bg, $input_type, $input_path, $output_ext, $output_filename);
|
||||||
$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
|
$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);
|
exec($cmd, $output, $ret);
|
||||||
if ($ret != 0) {
|
if ($ret != 0) {
|
||||||
@ -1024,7 +1051,7 @@ class Media extends Extension
|
|||||||
return in_array(self::normalize_format($format), self::ALPHA_FORMATS);
|
return in_array(self::normalize_format($format), self::ALPHA_FORMATS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function is_input_supported($engine, $format, ?bool $lossless = null): bool
|
public static function is_input_supported(string $engine, string $format, ?bool $lossless = null): bool
|
||||||
{
|
{
|
||||||
$format = self::normalize_format($format, $lossless);
|
$format = self::normalize_format($format, $lossless);
|
||||||
if (!in_array($format, MediaEngine::INPUT_SUPPORT[$engine])) {
|
if (!in_array($format, MediaEngine::INPUT_SUPPORT[$engine])) {
|
||||||
@ -1033,9 +1060,9 @@ class Media extends Extension
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function is_output_supported($engine, $format): bool
|
public static function is_output_supported(string $engine, string $format, ?bool $lossless = false): bool
|
||||||
{
|
{
|
||||||
$format = self::normalize_format($format);
|
$format = self::normalize_format($format, $lossless);
|
||||||
if (!in_array($format, MediaEngine::OUTPUT_SUPPORT[$engine])) {
|
if (!in_array($format, MediaEngine::OUTPUT_SUPPORT[$engine])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -170,12 +170,12 @@ class ResizeImage extends Extension
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function can_resize_format($format, ?bool $lossless): bool
|
private function can_resize_format($format, ?bool $lossless = null): bool
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
$engine = $config->get_string(ResizeConfig::ENGINE);
|
$engine = $config->get_string(ResizeConfig::ENGINE);
|
||||||
return Media::is_input_supported($engine, $format)
|
return Media::is_input_supported($engine, $format, $lossless)
|
||||||
&& Media::is_output_supported($engine, $format);
|
&& Media::is_output_supported($engine, $format, $lossless);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -183,12 +183,19 @@ class ResizeImage extends Extension
|
|||||||
/* ----------------------------- */
|
/* ----------------------------- */
|
||||||
private function resize_image(Image $image_obj, int $width, int $height)
|
private function resize_image(Image $image_obj, int $width, int $height)
|
||||||
{
|
{
|
||||||
global $database;
|
global $database, $config;
|
||||||
|
|
||||||
if (($height <= 0) && ($width <= 0)) {
|
if (($height <= 0) && ($width <= 0)) {
|
||||||
throw new ImageResizeException("Invalid options for height and width. ($width x $height)");
|
throw new ImageResizeException("Invalid options for height and width. ($width x $height)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$engine = $config->get_string(ResizeConfig::ENGINE);
|
||||||
|
|
||||||
|
|
||||||
|
if(!$this->can_resize_format($image_obj->ext, $image_obj->lossless)) {
|
||||||
|
throw new ImageResizeException("Engine $engine cannot resize selected image");
|
||||||
|
}
|
||||||
|
|
||||||
$hash = $image_obj->hash;
|
$hash = $image_obj->hash;
|
||||||
$image_filename = warehouse_path(Image::IMAGE_DIR, $hash);
|
$image_filename = warehouse_path(Image::IMAGE_DIR, $hash);
|
||||||
|
|
||||||
@ -206,7 +213,7 @@ class ResizeImage extends Extension
|
|||||||
}
|
}
|
||||||
|
|
||||||
send_event(new MediaResizeEvent(
|
send_event(new MediaResizeEvent(
|
||||||
MediaEngine::GD,
|
$engine,
|
||||||
$image_filename,
|
$image_filename,
|
||||||
$image_obj->ext,
|
$image_obj->ext,
|
||||||
$tmp_filename,
|
$tmp_filename,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user