Jump to content

$image->webp->url delivers a png-Url


Recommended Posts


what I'm doing is this:

	<source srcset="<?php echo $page->section_three->main_img->first()->size(396,710)->webp->url; ?>" type="image/webp">
	<img class="p_absoulte pp_block" src="<?php echo $page->section_three->main_img->first()->size(396,710)->url; ?>" alt="">

and for some reason it sometimes becomes this:

	<source srcset="/site/assets/files/1057/sektion3_bild-1.396x710.png" type="image/webp">
	<img class="p_absoulte pp_block" src="/site/assets/files/1057/sektion3_bild-1.396x710.png" alt="">

It seems to be related to ->size(). When I don't use ->size() the webp Url is correct.
I'm using the image-field inside a Fieldset(Page). Could that be a problem too?

I just increased the output size by 2px and voila the webp url comes up. 
I deleted all variations (webp variation is present in correct size) changed it back to the original size and again: a png url.

I also tried to rename the image and load it up agian. 

...same behavoir.

Thanks in advance guys

Link to comment
Share on other sites

Hi @eutervogel,

I believe it has to do with a automatic optimization that Ryan has build into the webp->url method. Given that webp is used to get smaller filesizes, and that sometimes a png or jpeg can be smaller than its webp pendant, the smaller one of them is put out by the webp->url. In general a nice idea, but only when one output a single src url in an img tag. For the more advanced usage in picture or srcset elements it is wrong and also irritating the devs.

If I remember right, there must be a config setting to disable this. If I find it, I post it here. If someone else reading this and knows where it is and how it is named, please shime in!

Link to comment
Share on other sites

$config->webpOptions = array(
    'quality' => 90, // Quality setting of 1-100 where higher is better but bigger
    'useSrcExt' => false, // Use source file extension in webp filename? (file.jpg.webp rather than file.webp)
    'useSrcUrlOnSize' => true, // Fallback to source file URL when webp file is larger than source?
    'useSrcUrlOnFail' => true, // Fallback to source file URL when webp file fails for some reason?

Set  'useSrcUrlOnSize' to false?

  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Similar Content

    • By skeltern
      WebP image support is great and works fine. But once created I've issues to get rid of all API generated WebP variations.
      The backend image field variations "Delete" works and I can remove all variations JPEG plus WebP. Image list is clean but all WebP API variations are still stored in file system (for instance files/12345/84.900x675.webp etc). I can only use ImageSizer with temp 'force' option to request fresh WebP variations or have to delete WebP files from folders. No other way so far. Tested with 2 sites and latest master PW 3.0.165.
      Is there somewhere a "magic button" or config/setup thing to solve my sticky WebP issue?
    • By thausmann
      Hey, I'm trying to completely switch over to WebP and noticed some strange behaviour. Let's say I upload a PNG in Processwire of size 1280x800.
      $page->image->url ➝ correct URL (filename.webp) $page->image->width(800)->url ➝ correct URL (filename.800x0.webp) $page->image->width(1280)->url ➝ wrong URL (filename.1280x0.png), webp file is not generated $page->image->width(1280)->url(false) ➝ correct URL (filename.1280x0.webp) but webp file is not generated So: When I request a size that equals the original file, no WebP conversion is happening (no webp file is created, although a new PNG is generated (...1280x0.png)).
      When I use url(false), I get the expected URL but still the file is not generated. Also interesting: this issue is only occuring with PNG, not JPG.
      My Configuration:
      $config->imageSizerOptions('webpAdd', true);  $config->imageSizerOptions('defaultGamma', -1); GD Pageimage::url Hook from here  Also tried to output width(1280)->webp->url, it makes no difference I checked that the PNG version is not smaller in filesize (PNG=450KB, WebP (from other tool)=60KB) Tested with Processwire 3.0.148 and 3.0.160 dev I think this post is about the same issue and where I got the url(false) from. Setting 'useSrcUrlOnFail' => false inside $config->webpOptions results in correct output URL (filename.1280x0.webp), but still the file is not generated. So maybe the webp conversion fails? Apparently I see zero webp logs in logs/image-resizer.txt  
      "Don't use resize" seems like a solution here but this is a generic approach in my code, sometimes uploaded images are simply already in the correct size. 
      Any ideas how to fix this and always get dem sweet sweet WebP images? Or did I find a bug?
      Maybe @horst has an idea what the cause of this phenomenon could be? 😇
    • By ThierryGD
      Hi there,
      I've been resizing some .png and got some pretty visible loss of quality. I attached those for comparison - around the Titanic (I know, they're big).
      I tried to find similar threads but couldn't find anything that helped - at least it made me install Horsts IMagick Image Sizer.  
      foreach($detailrp->detail_repeater_bild as $pRetinaBild) { if ($pRetinaBild->width > $pRetinaBild->height) { // 3320px wide $pHighBild = $pRetinaBild->size(1660, 0); $pLowBild = $pRetinaBild->size(830, 0); } else { // 3220px high $pHighBild = $pRetinaBild->size(0, 1610); $pLowBild = $pRetinaBild->size(0, 805); } Anyone has any idea what causes this and how to solve it? Or should I just go with .jpg? Thx!

    • By Peter Knight
      Is anyone here using WEBP as their output image format and what is your server / environment setup?
       I know there's support for it in PW lately and decided to investigate.
      Found it quite difficult to do this on a practical level. IE My current VPS is Cent OS 6 and Plesk and unless I'm wrong, WEBP is not supported by either.
      Which host and setup are you on that allows you to run WebP?
    • By klikrzys
      Hello processwire world!
      Im having a little problem with getting my image in WEBP format.
      $image = $pages->get('/')->images->first();             echo $image->webp()->url();
  • Create New...