In this tutorial, we will introduce you how to convert a webp image to png using python pillow. This example is very useful if you have got some webp image from internet.
We can import python pillow library firstly.
from PIL import Image
Read a webp image
In order to convert webp to png, we should read a webp image data.
Here is an example:
image_webp = 'chart.webp' image_png = 'chart.png' im = Image.open(image_webp)
Then we can start to convert.
Convert webp to png
im.save(image_png, format="png", lossless=True)
In this example code, we will use im.save() function to convert.
However, we should notice: the png image is bigger than webp. Here is the comparison.
If you want to convert png to webp, you can read: