WebP not moved to media folder

Hi,

I’m trying to output webP images but although they exist in the content folder, they don’t get generated into the media folder. They return 404s instead. I assume it’s the rather seemingly hacky way I’m trying to retrieve the webP version:

<?= str_replace(".png", ".webp", $image->url())  ?>

I don’t technically know the full filename to use the other method, is there a way I can specify what extension my preference is via ->url()?

I’m using Kirby version 3.3.6 so webp should be supported. Note I ran a convertor external to kirby on the PNGs rather than upload the webp via the panel.

Any help appreciated!

For the images to end up in the media folder, their URL must be called, so your string replacement won’t

https://getkirby.com/docs/reference/objects/page/imagework. You would have to find the webp version (e.g. using $page->image(), then call the URL on this file).

That didn’t seem to be it, I’ve refactored it so that it’s now using $image_url() by applying a findby on the image collection for webps.

Now $image->url() returns /media/pages/dates/2020-11-10/mail/974748285-1605796937/2020-11-10-mail-hd-400x.webp

But that file is 404ing. It exists in /content/ and renders so isn’t a mime/htaccess issue.

What does that mean? Could you please post your code?

Ah sorry I meant $image->url()

If I upload the webp manually in the admin it works - so it seems that I need to run it through the CMS to associate webps - it doesn’t do this on the fly as the file never existed according to Kirby. Most likely because I created these images externally so the job files for that webp doesn’t exist.

I’ll close this since it’s probably just an edge case and not an inherit kirby issue.

As I wrote, if you post your code, I’m sure we will find a solution. This has been done before and its just a matter of fetching the right file.

<?php   
 if($image = $newspaper->images()->findBy('template', 'newspaper-headline')->findBy('filename', 'webp')):
?>

<img <?php e($i == 0, '', 'data-') ?>src="<?= $image->url()  ?>" 
width="<?= $image->width() ?>" height="<?= $image->height() ?>" alt="<?= $newspaper->title() ?>">

Is the filename of the file you are looking for really webp? I’d think that is just the extension.

Yeah I misread the documentation for findBy, works on exact match unless you include an extra parameter.

Ended up using filterBy() for the extension.

And then it turned out the reason it’s not picking them up is because they don’t have their .txt file equivalent, since I just pasted all my webPs in. When you do it through the CMS it creates the .txt which is why that worked. I assume the images() call uses the txt files to work out the folder contents rather than looking at the image files for sake of speed.

The meta data text file is important for the template filtering, not for finding the file. Because the template is information stored in the meta data file.

1 Like