HUGO

How to optimise images in a particular folder and dump them in another folder in hugo at build time

Hi Developers,

Please is there a way in hugo to target a folder in the root directory and convert/compress all the images in them to a new format at build time.

For instance

I want to target all the jpeg/png images in static/images and convert them into webp at varying sizes then dump them in static/images/webp

I can explain further, if you have an question.

You cannot “transform” anything in static folder.

You have to put them in your assets folder.
Then you can use images transform functions.
The resulting images will have their own new name.

So I do not know why you want a new folder name, but i suspect that having a brand new name (and url) will suits you.

Difficult to give a better response without knowing why you want this “new folder”.

1 Like

For Jekyll there was Imagemagick, but I haven’t found a similar alternative for Hugo.

Hugo does however have good image processing functionality: Image Processing | Hugo
See here for information on converting to webp: Hugo 0.83: WebP Support! | Hugo