Script: Convert image file type from webp to jpg (or other file type) in Windows

Here is a short Python script to convert images from “webp” to “jpg” file type.

The script will create a new version with the “jpg” file type for each file with a “webp” found in the specified folder.

This script can easily be modified to convert from and to any common image file type.


# CONVERT FROM WEBP TO JPG
import glob
from PIL import Image

for name in glob.glob('[FULL PATH]\*.webp'): #FULL PATH of the location where the files are located.  Selects all the files with a ".webp" file type from the specified location.
	size = len(name)
	im=Image.open(name).convert("RGB")
	im.save(name[:size - 4] + 'jpg', "jpeg") #Saves the file with the original name and replaces the old extension with the desired extension; which in this case is "jpg".

print("Process Completed")

For safety reasons, this script creates a new version of the file with the new file type but will not delete the original file from the folder.

Note: If this script is to be used to convert a file type of only 3 characters, such as “.gif”, the “-4” should be substituted with a “-3” in the command used to save the new file.