How to convert webp image file format to jpeg image format using python

neotam Avatar

How to convert webp image file format to jpeg image format using python
Posted on :
,

Tags :

WebP is the image format that provides the effective lossy and lossless compression compared with other formats like PNG and JPEG for images on the web. Using WebP formats makes the web faster with smaller footprint images that stunning in terms of quality. Lossless compression of WebP images are 26% smaller in site relative to image format PNG while lossy compression of WebP images yield 25-34% smaller images compared to JPEG images. Such that, when you site is loaded with lot of images, using WebP make the website load faster, giving the use immense faster web experience.

Another major advantage of using WebP image format for web is that, they support alpha channel that is transparency while providing 3 timers smaller file sizes compared to PNG. WebP supports animated images like GIF with reduced sizes.

Usage of WebP format for images on the web instead of PNG or GIF make the website dramatically faster

Convert webp to jpeg using PIL

from PIL import Image
im = Image.open("image_to_convert.webp").convert("RGB")
im.save("new_image.jpeg", "jpeg")

Convert webp to jpeg using OpenCV and PIL

from PIL import Image
import cv2
img = cv2.imread("image_to_convert.webp")
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)  # OpenCV uses BGR color space by default 
Image.fromarray(img).save("image_to_convert.jpeg", "jpeg")

Convert webp format to jpeg using webptools


dwebp(input_image="python_logo.webp", output_image="python_logo.jpg",
            option="-o", logging="-v")

Convert JPEG to WebP

Convert JPEG image to WebP image format using webptools library

from webptools import cwebp 

cwebp(input_image="python_logo.jpg", output_image="python_logo.webp",
            option="-q 80", logging="-v")

Command line tools dwebp and cwebp can be used to convert image from and to webp image formats. Command line tools cwebp is used to compress an image of any format to WebP format. cwebp converts input image of format PNG, JPEG, TIFF to WebP format.

As discussed, WebP format also supports the encoding of multiple frames to create animated images. Command line tools img2webp can be used to make animated WebP image from sequence input image files

Leave a Reply

Your email address will not be published. Required fields are marked *