1
0
mirror of https://github.com/e107inc/e107.git synced 2025-04-20 04:32:01 +02:00

Issue #4270 Added .webp browser-support detection. Media-Manager "Convert to webp during render" can now be safely enabled and will temporarily fallback to the regular image if the browser does not support webp images.

This commit is contained in:
Cameron 2021-06-18 08:43:53 -07:00
parent a89b58a8a2
commit 7302803a75
3 changed files with 19 additions and 8 deletions

View File

@ -419,7 +419,7 @@ $sysprefs = new prefs;
//DEPRECATED, BC, call e107::getPref/findPref() instead
if(e_ADMIN_AREA !== true && !isset($_E107['no_parser']) && !empty($pref['thumb_to_webp']))
if(e_ADMIN_AREA !== true && !isset($_E107['no_parser']) && !empty($pref['thumb_to_webp']) && (strpos( $_SERVER['HTTP_ACCEPT'], 'image/webp' ) !== false))
{
$tp->setConvertToWebP(true);
}

View File

@ -2361,6 +2361,11 @@ class e_parse
parse_str($options, $options);
}
if($this->convertToWebP)
{
$options['type'] = 'webp';
}
if(!empty($options['scale'])) // eg. scale the width height 2x 3x 4x. etc.
{
$options['return'] = 'src';
@ -2559,6 +2564,7 @@ class e_parse
}
// $encode = $this->thumbEncode();;
if($width == null || $width === 'all')
{
@ -4345,17 +4351,16 @@ class e_parse
}
$html = '';
/*
if($this->convertToWebP)
{
$parm['type'] = 'webp';
$source = $tp->thumbUrl($file, $parm);
$html = "<picture class=\"{$class}\">\n";
if(!empty($parm['srcset']))
{
list($webPSourceSet, $webPSize) = explode(' ', $parm['srcset']);
$html .= '<source type="image/webp" srcset="' . $webPSourceSet . '&amp;type=webp ' . $webPSize . '">';
$html .= '<source type="image/webp" srcset="' . $webPSourceSet . ' ' . $webPSize . '">';
$html .= "\n";
$html .= '<source type="image/' . str_replace('jpg', 'jpeg', $ext) . '" srcset="' . $parm['srcset'] . '">';
$html .= "\n";
@ -4364,7 +4369,7 @@ class e_parse
$html .= '<source type="image/webp" srcset="' . $source . '">';
$html .= "\n";
}
}*/
if(empty($path))
{
@ -4373,7 +4378,7 @@ class e_parse
$html .= "<img {$id}class=\"{$class}\" src=\"" . $path . '" alt="' . $alt . '" ' . $srcset . $width . $height . $style . $loading . $title . ' />';
$html .= ($this->convertToWebP) ? "\n</picture>" : '';
// $html .= ($this->convertToWebP) ? "\n</picture>" : '';
return $html;

View File

@ -1192,6 +1192,11 @@ while(&#036;row = &#036;sql-&gt;fetch())
'options' => array('w'=>300, 'h'=>200, 'scale'=>'2x'),
'expected' =>'/thumb.php?src=e_PLUGIN%2Fgallery%2Fimages%2Fbutterfly.jpg&amp;w=600&amp;h=400'
),
4 => array(
'path' => '{e_PLUGIN}gallery/images/horse.jpg',
'options' => array('w'=>300, 'h'=>200, 'scale'=>'2x', 'type'=>'webp'),
'expected' =>'/thumb.php?src=e_PLUGIN%2Fgallery%2Fimages%2Fhorse.jpg&amp;w=600&amp;h=400&amp;type=webp'
),
);
@ -2298,14 +2303,15 @@ while(&#036;row = &#036;sql-&gt;fetch())
$this->tp->setConvertToWebP(true);
$result6 = $this->tp->toImage($src);
$expected = '<img class="img-responsive img-fluid" src="thumb.php?src=e_PLUGIN%2Fgallery%2Fimages%2Fbutterfly.jpg&amp;w=80&amp;h=80&amp;type=webp" alt="butterfly.jpg" srcset="thumb.php?src=e_PLUGIN%2Fgallery%2Fimages%2Fbutterfly.jpg&amp;w=320&amp;h=320&amp;type=webp 4x" width="80" height="80" />';
/*
$expected = '<picture class="img-responsive img-fluid">
<source type="image/webp" srcset="thumb.php?src=e_PLUGIN%2Fgallery%2Fimages%2Fbutterfly.jpg&amp;w=320&amp;h=320&amp;type=webp 4x">
<source type="image/jpeg" srcset="thumb.php?src=e_PLUGIN%2Fgallery%2Fimages%2Fbutterfly.jpg&amp;w=320&amp;h=320 4x">
<source type="image/webp" srcset="thumb.php?src=e_PLUGIN%2Fgallery%2Fimages%2Fbutterfly.jpg&amp;w=80&amp;h=80&amp;type=webp">
<img class="img-responsive img-fluid" src="thumb.php?src=e_PLUGIN%2Fgallery%2Fimages%2Fbutterfly.jpg&amp;w=80&amp;h=80" alt="butterfly.jpg" width="80" height="80" />
</picture>';
</picture>';*/
// $tempDir = str_replace(['C:','\\'],['','/'], sys_get_temp_dir()).'/'; // FIXME
$result6 = preg_replace('/"([^"]*)thumb.php/','"thumb.php', $result6);