Convert Webp images to PNG by Linux command

How to convert .webp images to .png on Linux

Tested on Linux Ubuntu 20.04

This question is the top hit for the Google search of "linux convert .webp image to png". Therefore, for anyone stumbling here and just wanting that simple answer, here it is:

# 1. Install the `webp` tool
sudo apt update
sudo apt install webp

# 2. Use it: convert in.webp to out.png
dwebp in.webp -o out.png

Done! You now have out.png.

References

  1. I learned about dwebp from the question itself

If you have many to convert/rename, I would recommend you use GNU Parallel and not only get them converted faster by doing them I parallel, but also take advantage of the ability to modify filenames.

The command you want is:

parallel dwebp {} -o {.}.png ::: *.jpg

where the {.} means "the filename without the original extension".

If you want to recurse into subdirectories too, you can use:

find . -name "*.jpg" -print0 | parallel -0 dwebp {} -o {.}.png

If you want a progress meter, or an "estimated time of arrival", you can add --progress or --eta after the parallel command.

If you want to see what GNU Parallel would run, without actually running anything, add --dry-run.

I commend GNU Parallel to you in this age where CPUs are getting "fatter" (more cores) rather than faster.


I did it with short oneliner that does not require parallel to be installed in the system

for x in `ls -1 *.jpg`; do dwebp {} -o ${x%.*}.png ::: $x; done

And this works for current directory

I would try to amend the @mark-setchell recursive solution so it would look like this:

for x in `find . -name "*.jpg"`; do dwebp {} -o ${x%.*}.png ::: $x; done

The ${x%.*} part is the one requiring a word of explanation here - it tells bash to take . and everything after the dot from the x variable. It is prone to misbehave for names with more dots as I did not check if regex here is lazy or greedy - the answer can be tuned further therefore.