Jump to content

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


eutervogel
 Share

Recommended Posts

Hi, 

what I'm doing is this:
 

 <picture>
	<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="">
</picture>

and for some reason it sometimes becomes this:

<picture>
	<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="">
</picture>

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
 Share

×
×
  • Create New...