# Webp not working

**URL:** <https://forum.getkirby.com/t/webp-not-working/25538>\
**Category:** Questions\
**Tags:** v3\
**Created:** [May 19, 2022, 8:16pm UTC](https://forum.getkirby.com/t/webp-not-working/25538 "2022-05-19T20:16:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![afplaktape](https://avatars.discourse-cdn.com/v4/letter/a/4da419/32.png) [@afplaktape](https://forum.getkirby.com/u/afplaktape)\
**Post date:** [May 19, 2022, 8:16pm UTC](https://forum.getkirby.com/t/webp-not-working/25538/1 "2022-05-19T20:16:55Z")

</div>

Hi, I’m trying to get the webp plugin from hash and salt by @jimbobrjames to work on my website

I’ve downloaded the latest version of the plugin and put it in the plugins folder.

In my template I use the following snippet:

```auto
<?php snippet('webp', ['sizes' => [1920, 1140, 640, 320], 'src' => 'this-is-an-image.png', 'type' => 'png', 'class' => 'picturetagclass', 'width' => 800, 'height' => 600]) ?>

```

But I get the following error: Call to a member function toWebp() on string

Can’t seem to figure out how to get it up and running. Any advice?

---

<div class="post-metadata">

**Author:** ![ahmetbora](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/ahmetbora/32/11671_2.png) [@ahmetbora](https://forum.getkirby.com/u/ahmetbora)\
**Post date:** [May 19, 2022, 8:39pm UTC](https://forum.getkirby.com/t/webp-not-working/25538/2 "2022-05-19T20:39:55Z")

</div>

> [@afplaktape](#):
>
> `'src' => 'this-is-an-image.png'`

I guess, `src` needs to be `File` object, not string. Something like that:

```php
'src' => $page->cover()->toFile()

```

---

<div class="post-metadata">

**Author:** ![jimbobrjames](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jimbobrjames/32/5802_2.png) [@jimbobrjames](https://forum.getkirby.com/u/jimbobrjames)\
**Post date:** [May 19, 2022, 9:30pm UTC](https://forum.getkirby.com/t/webp-not-working/25538/3 "2022-05-19T21:30:12Z")

</div>

This plugin was made for Kirby versions prior to 3.6. That version supports Webp out the box, and you no longer need my plugin. I would suggest swapping to that if you can.

---

<div class="post-metadata">

**Author:** ![afplaktape](https://avatars.discourse-cdn.com/v4/letter/a/4da419/32.png) [@afplaktape](https://forum.getkirby.com/u/afplaktape)\
**Post date:** [May 20, 2022, 7:47am UTC](https://forum.getkirby.com/t/webp-not-working/25538/4 "2022-05-20T07:47:38Z")

</div>

Thanks! Is there a more elaborate documentation on how to implement webp images in kirby than [this](https://getkirby.com/docs/guide/templates/resize-images-on-the-fly)?

I’ve added this to my config file

```auto
    'thumbs' => [
        'driver' => 'im',
        'format' => 'webp',
        'bin' => '/usr/local/bin/convert',
        'interlace' => true,
    ]

```

And using this in my template:

```auto
<?= $img->toFile()->thumb(['width' => 400, 'format' => 'webp', 'quality' => 10]) ?>

```

which does serve me this file on my website:

```auto
/image-400x-q10.webp

```

It does seem to work according to the file name but the image is shown in high quality (over 1mb) and the cropping I used before isn’t working as either one of these:

```auto
$image->toFile()->crop(1080, 1420, 'center right')->thumb();
$image->toFile()->thumb(['crop' => 1080, 1420, 'format' => 'webp', 'quality' => 10])

```

---

<div class="post-metadata">

**Author:** ![afplaktape](https://avatars.discourse-cdn.com/v4/letter/a/4da419/32.png) [@afplaktape](https://forum.getkirby.com/u/afplaktape)\
**Post date:** [May 20, 2022, 9:13am UTC](https://forum.getkirby.com/t/webp-not-working/25538/5 "2022-05-20T09:13:08Z")

</div>

Update: Switching to the gd driver helped me out (although imagick is also turned on). However I still don’t know how to properly crop the image to different aspect ratio like

```auto
->crop(1080, 1420, 'center right')

```

would do.

---

<div class="post-metadata">

**Author:** ![rasteiner](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/rasteiner/32/4788_2.png) [@rasteiner](https://forum.getkirby.com/u/rasteiner)\
**Post date:** [May 20, 2022, 9:51am UTC](https://forum.getkirby.com/t/webp-not-working/25538/6 "2022-05-20T09:51:10Z")

</div>

> [@afplaktape](#):
>
> although imagick is also turned on

is `'/usr/local/bin/convert'` correct?  
in a shell, try typing `which convert` and see what it gives you.

> [@afplaktape](#):
>
> ```auto
> $image->toFile()->thumb(['crop' => 1080, 1420, 'format' => 'webp', 'quality' => 10])
> 
> ```

```auto
$image->toFile()->thumb([
  'crop' => true,
  'width' => 1080,
  'height' => 1420,
  'format' => 'webp',
  'quality' => 10
])

```

---

<div class="post-metadata">

**Author:** ![afplaktape](https://avatars.discourse-cdn.com/v4/letter/a/4da419/32.png) [@afplaktape](https://forum.getkirby.com/u/afplaktape)\
**Post date:** [May 20, 2022, 10:06am UTC](https://forum.getkirby.com/t/webp-not-working/25538/7 "2022-05-20T10:06:28Z")

</div>

> [@rasteiner](#):
>
> is `'/usr/local/bin/convert'` correct?

I don’t really know what ‘bin’ does. Just copied this from [this](https://getkirby.com/docs/guide/templates/resize-images-on-the-fly#configuring-your-thumbnails) section in order to get it working 😬

Thanks for showing me to right way to crop. Is there also a way to use ‘center right’ as cropping reference?

---

<div class="post-metadata">

**Author:** ![rasteiner](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/rasteiner/32/4788_2.png) [@rasteiner](https://forum.getkirby.com/u/rasteiner)\
**Post date:** [May 23, 2022, 11:59am UTC](https://forum.getkirby.com/t/webp-not-working/25538/8 "2022-05-23T11:59:20Z")

</div>

> [@afplaktape](#):
>
> I don’t really know what ‘bin’ does. Just copied this from [this](https://getkirby.com/docs/guide/templates/resize-images-on-the-fly#configuring-your-thumbnails) section in order to get it working 😬

Hi, the `im` driver relies on a command line program to be available. That is `convert`. This program could however be either not installed at all, or be installed in different locations (on my local machine, for example it is in `/usr/bin/convert`, but it literally could be anything).  
If you have imagemagick installed (of which `convert` is a part), you can write the command `which convert` in a shell and it will normally give you the correct path to where it can be found; or tell you if it isn’t.

> [@afplaktape](#):
>
> Is there also a way to use ‘center right’ as cropping reference?

I think

```php
$image->toFile()->thumb([
  'crop' => 'center right',
  'width' => 1080,
  'height' => 1420,
  'format' => 'webp',
  'quality' => 10
])

```

should do 🙂
