# Can hugo convert all images to WEBP after the update?

**URL:** <https://discourse.gohugo.io/t/can-hugo-convert-all-images-to-webp-after-the-update/32893>\
**Category:** support\
**Created:** [May 15, 2021, 5:57am UTC](https://discourse.gohugo.io/t/can-hugo-convert-all-images-to-webp-after-the-update/32893 "2021-05-15T05:57:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yousafblogger](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/yousafblogger/32/14778_2.png) [@yousafblogger](https://discourse.gohugo.io/u/yousafblogger)\
**Post date:** [May 15, 2021, 5:57am UTC](https://discourse.gohugo.io/t/can-hugo-convert-all-images-to-webp-after-the-update/32893/1 "2021-05-15T05:57:21Z")

</div>

I have all the images stored in static/uploads folder.  
Also I grab some images from other urls.

I want hugo to download and convert those images to webp whenever site is published and show them on the website.

Is there any way?

---

<div class="post-metadata">

**Author:** ![idarek](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/idarek/32/26229_2.png) [@idarek](https://discourse.gohugo.io/u/idarek)\
**Post date:** [May 15, 2021, 6:28am UTC](https://discourse.gohugo.io/t/can-hugo-convert-all-images-to-webp-after-the-update/32893/2 "2021-05-15T06:28:34Z")

</div>

Not without amending `render-image.html`. See [here](https://gohugo.io/content-management/image-processing/)

Also, would recommend to let hugo Generate WebP images locally and sync `resources/_gen/assets` with your git as this will avoid time that will take to gen them on server side like Netlify.

There is also different approach to WebP that was working and I been using before WebP was originally introduced in Hugo 0.83. Yuo can convert all images using following command (on mac):

```auto
`find ./ -type f -name '*.png' -exec sh -c 'cwebp -q 75 $1 -o "${1%.png}.webp"' _ {} \;`
  `find ./ -type f -name '*.jpg' -exec sh -c 'cwebp -q 75 $1 -o "${1%.jpg}.webp"' _ {} \;`

```

You need brew webp for that,

and later call them according to this [post](https://pawelgrzybek.com/webp-and-avif-images-on-a-hugo-website/) in `render-image.html`

Mine looks as follow:

```auto
{{- $image := resources.Get .Destination -}}

  <picture>
    {{ $isJPG := eq (path.Ext .Destination) ".jpg" }}
    {{ $isPNG := eq (path.Ext .Destination) ".png" }}

    {{ if ($isJPG) -}}
      {{ $webp:= resources.Get (replace .Destination ".jpg" ".webp") }}
        <source srcset="{{ $webp.Permalink | safeURL }}" type="image/webp" >
    {{- end }}

    {{ if ($isPNG) -}}
      {{ $webp:= resources.Get (replace .Destination ".png" ".webp") }}
        <source srcset="{{ $webp.Permalink | safeURL }}" type="image/webp" >
    {{- end }}

    <img
      src="{{ $image.Permalink | safeURL }}"
      sizes="100vw"
      alt="{{ .Title }}" title="{{ .Title }}"
      loading="lazy"
      decoding="async"
      width="{{ $image.Width }}"
      height="{{ $image.Height }}"
    />
  </picture>

```

Using 2nd methiod I got full control on my images and they don’t need to be re-generated when something change etc.

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [May 15, 2021, 7:36am UTC](https://discourse.gohugo.io/t/can-hugo-convert-all-images-to-webp-after-the-update/32893/3 "2021-05-15T07:36:35Z")

</div>

> [@yousafblogger](#):
>
> Is there any way?

What you can do is to store the images (or mount it) inside /assets. Then you can use `resources.Match` to list all the images you want, and then you can convert them to webp and show them.
