Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch process .png to .webp [closed]

Tags:

bash

image

png

webp

I have around 100 .png images, and all of them have to be converted to .webp (Google's image format). I am using Google's CLI tool. Any idea how to batch process them.

like image 462
user2111006 Avatar asked Oct 25 '14 17:10

user2111006


People also ask

Why is PNG downloading as WEBP?

Google's proprietary image format WEBP is arguably better than the standard JPG or PNG format. It creates a much smaller file size than JPG and still supports the transparency feature of PNG without much loss in quality.

Can you convert PNG to WEBP?

CloudConvert converts your image files online. Amongst many others, we support PNG, JPG, GIF, WEBP and HEIC. You can use the options to control image resolution, quality and file size.

How do I save a PNG file without WEBP?

Use a browser that does not support webp You can run Firefox or Internet Explorer instead for all your image downloading needs, so that the images are automatically saved as png or jpg images. If you rely on Chrome, try the User Agent Switcher extension instead which fakes the browser you are using.

Why will images only save as WEBP?

Webp is a image format developed by Google for web graphics, you can rename the file using file. jpeg naming to open it normally, this happens because there are many extensions like jpeg, png, bmp, webp, Google saves image in webp format because it was originally webp image not jpeg I guess.


2 Answers

You can do it with a help of a simple bash script.

Navigate to the directory where your images reside and execute this:

$ for file in * > do > cwebp -q 80 "$file" -o "${file%.png}.webp" > done 

You can change the output file name, as you want. But should end with a .webp extension.

like image 79
InfinitePrime Avatar answered Oct 25 '22 14:10

InfinitePrime


You need to use GNU Parallel if you have that many, or you will be there all year!

Please copy a few files into a spare temporary directory first and try this there to be sure it does what you want before using it on 100,000 images:

parallel -eta cwebp {} -o {.}.webp ::: *.png 

That will start, and keep running, as many processes as you have CPU cores, each doing a cwebp. The files processed will be all the PNG files in the current directory.

If the command line gets too long, you can pass the file list in using find like this:

find . -name "*.png" | parallel -eta cwebp {} -o {.}.webp 
like image 44
Mark Setchell Avatar answered Oct 25 '22 12:10

Mark Setchell