octfx / mediawiki-extension-WebP

Convert image files on upload to WebP
https://mediawiki.org/wiki/Extension:WebP
GNU General Public License v2.0
6 stars 4 forks source link

WebP images / thumbnails are created but webp srcsets in picture element are not added #20

Closed tsadrafoundation closed 8 months ago

tsadrafoundation commented 9 months ago

I have WebP on the develop branch with MW 1.39 & ImageMagik with WebP support.

The WebP images / thumbnails are created but additional srcsets with image/webp MIME type in the html element are missing.

PictureHtmlSupport extension is installed and /var/www/html/includes/media/ThumbnailImage.php is being replaced with /var/www/html/extensions/PictureHtmlSupport/includes/ThumbnailImage.php

The webp configutation is

$wgWebPEnableConvertOnUpload = true;
$wgWebPEnableConvertOnTransform = true;
# $wgWebPEnableResponsiveVersionJobs = true;
# $wgWebPCheckAcceptHeader = false;
$wgWebPCompressionQuality = 75;
$wgWebPCompressionQualityAvif = 75;
$wgWebPFilterStrength = 80;
$wgWebPAutoFilter = true;
# $wgWebPThumbSizes = [120, 320, 800, 1200, 1600];
$wgEnabledTransformers = [
"MediaWiki\\Extension\\WebP\\Transformer\\WebPTransformer"
#"MediaWiki\\Extension\\WebP\\Transformer\\AvifTransformer",
];
$wgWebPCWebPLocation = "/usr/bin/cwebp";
# $wgWebPAvifencLocation = /usr/bin/avifenc;

I've noticed that in ./extensions/WebP/includes/Hooks/ThumbnailHooks.php in the function:

public function onPictureHtmlSupportBeforeProduceHtml( ThumbnailImage $thumbnail, array &$sources ): void {

the first if the $thumbnail->getStoragePath() is null so it gets out of the function right away and the $srcset array is not populated.

tsadrafoundation commented 8 months ago

@octfx any tips on which direction should I troubleshoot?

Thank you !

tsadrafoundation commented 8 months ago

So now I'm able to see the <picture> element, and the srcset has the 1x, 1.5x and 2x but still no webp:

<picture>
<source srcset="/thumb.php?f=file.jpeg&amp;width=300, /thumb.php?f=file.jpeg&amp;width=450 1.5x, /thumb.php?f=file.jpeg&amp;width=600 2x"><img alt="" src="/thumb.php?f=file.jpeg&amp;width=300" decoding="async" width="300" height="462" class="thumbimage" data-file-width="1331" data-file-height="2048">
</picture>

The webp file is created in the images/webp path. I guess now the question is who takes care of that "redirect/rewrite"

octfx commented 8 months ago

Sorry for the very late reply, I’m currently not able to provide any support bugfixes (this will hopefully change in the following weeks)

I see that you are using a thumb handler (thumb.php) I haven’t testet ext:webp using thumb.php so there may be undiscovered issues. :/

You could try deactivating thumb.php and see if this changes things.

tsadrafoundation commented 8 months ago

@octfx yes, the issue is in using the the thumb handler.

I've commented out $wgThumbnailScriptPath and it worked.

Thanks!