# Hugo doesn't convert PNG to WebP

**URL:** <https://discourse.gohugo.io/t/hugo-doesnt-convert-png-to-webp/39247>\
**Category:** support\
**Created:** [June 25, 2022, 4:27pm UTC](https://discourse.gohugo.io/t/hugo-doesnt-convert-png-to-webp/39247 "2022-06-25T16:27:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![realpixelcode](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/realpixelcode/32/17189_2.png) [@realpixelcode](https://discourse.gohugo.io/u/realpixelcode)\
**Post date:** [June 25, 2022, 4:27pm UTC](https://discourse.gohugo.io/t/hugo-doesnt-convert-png-to-webp/39247/1 "2022-06-25T16:27:44Z")

</div>

I’m currently trying to improve the loading speed of my Hugo website [Grammle](https://grammle.codeberg.page) and just tried converting PNG images to WebP (because everyone always says WebP is much smaller than PNG).

I started with [this](https://grammle.codeberg.page/ueber/#ist-grammles-quellcode-einsehbar) “Get it on Codeberg” image. (The page is in German but you’ll recognise the image.)

I followed the [documentation about the target format](https://gohugo.io/content-management/image-processing/#target-format), and this is the code I use:

```auto
{{ with resources.Get "img/get-it-on-codeberg-neon-blue-with-bg.png" }}
  {{ with .Resize "400x webp" }}
    <a class="codeberg-banner-container" href="{{ site.Params.gitRepo }}">
      <img class="codeberg-banner" src="{{ .RelPermalink }}" alt="Get it on Codeberg">
    </a>
  {{ end }}
{{ end }}

```

You can view the Hugo directory at [Codeberg/Grammle/Grammle](https://codeberg.org/Grammle/Grammle/src/branch/master/grammle) and the output from running `hugo` at [Codeberg/Grammle/pages](https://codeberg.org/Grammle/pages).

The code above is from the [codebergBanner.html short code](https://codeberg.org/Grammle/Grammle/src/branch/master/grammle/layouts/shortcodes/codebergBanner.html), and the image is stored as `get-it-on-codeberg-neon-blue-with-bg.png` under [`assets/img`](https://codeberg.org/Grammle/Grammle/src/branch/master/grammle/assets/img/get-it-on-codeberg-neon-blue-with-bg.png).

**However, Hugo does not convert the PNG image to WebP at all. Why is that and how can I fix it?**

When replacing `webp` with `jpg` the image is in fact converted to JPG though, so the issue is not that the conversion wouldn’t work at all, it just doesn’t work for WebP.

Thank you!

---

<div class="post-metadata">

**Author:** ![realpixelcode](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/realpixelcode/32/17189_2.png) [@realpixelcode](https://discourse.gohugo.io/u/realpixelcode)\
**Post date:** [June 25, 2022, 4:38pm UTC](https://discourse.gohugo.io/t/hugo-doesnt-convert-png-to-webp/39247/2 "2022-06-25T16:38:57Z")

</div>

I also tried with [another image](https://grammle.codeberg.page/ueber/#darf-ich-grammle-selbst-weiterverwenden) and it didn’t work either:

```auto
{{ with resources.Get "img/fogeye-250.png" }}
  {{ with .Resize (printf "%dx%d webp" .Width .Height) }}
    <a class="fogeye-banner-container" href="{{ site.Params.licenceLink }}">
      <img class="fogeye-banner" src="{{ .RelPermalink }}" alt="For Good Eyes Only">
    </a>
  {{ end }}
{{ end }}

```

The code is from [`fogeye.html`](https://codeberg.org/Grammle/Grammle/src/branch/master/grammle/layouts/shortcodes/fogeye.html).

---

<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:** [June 25, 2022, 5:01pm UTC](https://discourse.gohugo.io/t/hugo-doesnt-convert-png-to-webp/39247/3 "2022-06-25T17:01:59Z")

</div>

- Do you see any error in the console?
- Do you run with the extended version of Hugo? What’s the output of `hugo version`?

---

<div class="post-metadata">

**Author:** ![realpixelcode](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/realpixelcode/32/17189_2.png) [@realpixelcode](https://discourse.gohugo.io/u/realpixelcode)\
**Post date:** [June 25, 2022, 5:07pm UTC](https://discourse.gohugo.io/t/hugo-doesnt-convert-png-to-webp/39247/4 "2022-06-25T17:07:00Z")

</div>

There are no errors, only a warning about some sloppy `IsSet` call:

```auto
$ hugo
Building sites … WARNING: calling IsSet with unsupported type "invalid" (<nil>) will always return false.

WARNING: calling IsSet with unsupported type "ptr" (*hugolib.pageState) will always return false.

                   | DE  
-------------------+-----
  Pages | 40  
  Paginator pages | 0  
  Non-page files | 0  
  Static files | 62  
  Processed images | 2  
  Aliases | 25  
  Sitemaps | 0  
  Cleaned | 0  

Total in 80 ms

```

Yes, apparently, I am in fact using the extended version:

```auto
$ hugo version
Hugo Static Site Generator v0.68.3/extended linux/amd64 BuildDate: 2020-03-25T06:15:45Z

```

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [June 25, 2022, 5:11pm UTC](https://discourse.gohugo.io/t/hugo-doesnt-convert-png-to-webp/39247/5 "2022-06-25T17:11:40Z")

</div>

Support for the WebP format was introduced in v0.83.0.

---

<div class="post-metadata">

**Author:** ![realpixelcode](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/realpixelcode/32/17189_2.png) [@realpixelcode](https://discourse.gohugo.io/u/realpixelcode)\
**Post date:** [June 25, 2022, 5:37pm UTC](https://discourse.gohugo.io/t/hugo-doesnt-convert-png-to-webp/39247/6 "2022-06-25T17:37:32Z")

</div>

Oh, I didn’t realise I’m that far behind the latest release. 🤯

However, I just ran `sudo apt-get update` and `sudo apt-get upgrade` but this didn’t update Hugo at all.

Running `sudo apt-get install hugo` returned: `hugo is already the newest version (0.68.3-1)`, so I completely uninstalled and re-installed Hugo but I still only got `v0.68.3` again.

That’s why I just re-installed hugo with `snap install hugo` which got me `v0.96.0`, and running `snap run hugo` did in fact convert the PNG to WebP!

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![techmagus](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/techmagus/32/16997_2.png) [@techmagus](https://discourse.gohugo.io/u/techmagus)\
**Post date:** [June 26, 2022, 4:35am UTC](https://discourse.gohugo.io/t/hugo-doesnt-convert-png-to-webp/39247/7 "2022-06-26T04:35:11Z")

</div>

Just an added tip, re: Hugo version. The latest release as of this post is v0.101.0.

Since you’re using sudo/snap … if you want the latest release you can download the appropriate .deb file from: [Releases · gohugoio/hugo · GitHub](https://github.com/gohugoio/hugo/releases)

Then just do: `sudo apt install ./hugo_extended_0.1xx.x_Linux-64bit.deb`

To be informed if there’s a new release, you can “Watch” the Github repo and have GH email you for updates.

As you can see, even Ubuntu’s snap is late.

It’s a little bit of a hassle doing it manually but at least you’ll always be at the latest release. Another added benefit, you can choose which version you want to stick at, you don’t necessarily have to update. Also you won’t get surprised if something stopped working because the OS auto-updated to a version with a deprecated/changed function (rare but might happen).

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [June 28, 2022, 4:35am UTC](https://discourse.gohugo.io/t/hugo-doesnt-convert-png-to-webp/39247/8 "2022-06-28T04:35:48Z")

</div>

Closed on June 28, 2022, 4:35am UTC

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
