diff --git a/docs/NEWS b/docs/NEWS index 6486adc53..0db850117 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -1,6 +1,13 @@ Version 2.6-alpha1 () ------------------------------------------------------------------------ + * Enable .webp and .avif thumbnails also when using PHP's gd module + instead of imagemagick. Optimize imagemagick's thumbnail parameters, + for smaller filesizes for .webp and .avif images. + NOTE: Check the new structure in serendipity_config.inc.php if you + have set a custom value for imagemagick_thumb_parameters in your + local config file. + * PHP 8.4 fix: Remove deprecated constant E_STRICT * PHP 8 compatibility fixes for bundled XML/RPC.php diff --git a/include/functions_images.inc.php b/include/functions_images.inc.php index 996ec117c..f54179741 100644 --- a/include/functions_images.inc.php +++ b/include/functions_images.inc.php @@ -735,7 +735,22 @@ function serendipity_makeThumbnail($file, $directory = '', $size = false, $thumb $newSize .= '>'; // tell imagemagick to not enlarge small images, only works if safe_mode is off (safe_mode turns > in to \>) } if (!$serendipity['imagemagick_nobang']) $newSize .= '!'; // force the first run image geometry exactly to given sizes, if there were rounding differences (see https://github.com/s9y/Serendipity/commit/94881ba4c0e3bdd4b5fac510e93977e239171c1c and comments) - $cmd = escapeshellcmd($serendipity['convert'] . ' ' . $serendipity['imagemagick_thumb_parameters']) . ' -antialias -resize ' . serendipity_escapeshellarg($newSize) . ' ' . serendipity_escapeshellarg($infile) .' '. serendipity_escapeshellarg($outfile); + + $params = '-sampling-factor 4:2:0 -unsharp 0x0.75+0.75+0.008 -strip -quality 85'; + if (is_string($serendipity['imagemagick_thumb_parameters'])) { + // In s9y < 2.6, $serendipity['imagemagick_thumb_parameters'] was a string and the default + // value targeted jpgs. Users might have set variants of that in their local config, so + // we provide a backwards compatibly path here + $params = $serendipity['imagemagick_thumb_parameters']; + } else { + // In 2.6 $serendipity['imagemagick_thumb_parameters'] has values for different + // image formats + if (isset($serendipity['imagemagick_thumb_parameters'][$fdim['mime']])) { + $params = $serendipity['imagemagick_thumb_parameters'][$fdim['mime']]; + } + } + + $cmd = escapeshellcmd($serendipity['convert'] . ' ' . $params) . ' -antialias -resize ' . serendipity_escapeshellarg($newSize) . ' ' . serendipity_escapeshellarg($infile) .' '. serendipity_escapeshellarg($outfile); } exec($cmd, $output, $result); if ($result != 0) { @@ -1318,6 +1333,18 @@ function serendipity_functions_gd($infilename) { $func['save'] = 'imagejpeg'; $func['qual'] = 85; break; + + case 'avif': + $func['load'] = 'imagecreatefromavif'; + $func['save'] = 'imageavif'; + $func['qual'] = 60; + break; + + case 'webp': + $func['load'] = 'imagecreatefromwebp'; + $func['save'] = 'imagewebp'; + $func['qual'] = 90; + break; case 'png': $func['load'] = 'imagecreatefrompng'; diff --git a/serendipity_config.inc.php b/serendipity_config.inc.php index 48537ad6b..4f5f2b389 100644 --- a/serendipity_config.inc.php +++ b/serendipity_config.inc.php @@ -496,7 +496,10 @@ // image quality when resizing. // // Set a variable like below in your serendpity_config_local.inc.php with your own settings - $serendipity['imagemagick_thumb_parameters'] = '-sampling-factor 4:2:0 -unsharp 0x0.75+0.75+0.008 -strip -quality 85 -interlace JPEG'; + $serendipity['imagemagick_thumb_parameters'] = [ 'image/jpeg' => '-sampling-factor 4:2:0 -unsharp 0x0.75+0.75+0.008 -strip -quality 85 -interlace JPEG', + 'image/avif' => '-sampling-factor 4:2:0 -unsharp 0x0.75+0.75+0.008 -strip -quality 60', + 'image/webp' => '-sampling-factor 4:2:0 -unsharp 0x0.75+0.75+0.008 -strip -quality 90' + ]; } serendipity_plugin_api::hook_event('frontend_configure', $serendipity); diff --git a/test.avif b/test.avif new file mode 100644 index 000000000..4d3e6db25 Binary files /dev/null and b/test.avif differ