Function Overview
This skill will help you convert WebP format images to JPG format so they can be used on platforms that do not support the WebP format.
Use Cases
- Use images on platforms that do not support the WebP format, such as WeChat Official Accounts
- Convert WebP images to the more universal JPG format
- Prepare image formats suitable for specific platforms
Conversion Steps
- Check the Pillow library: Confirm that the Pillow library is installed on the system for image processing
python -c "from PIL import Image; print('Pillow is available')"
-
Install the Pillow library(if it is not installed):
pip install Pillow -
Perform the format conversion:
from PIL import Image # 打开WebP图片 img = Image.open('<webp_image_path>') # 转换为RGB模式(因为JPG不支持透明度) rgb_img = img.convert('RGB') # 保存为JPG格式 rgb_img.save('<jpg_image_path>', 'JPEG')
Complete conversion command
Use the Python command line directly for conversion:
python -c "from PIL import Image; img = Image.open('<webp_image_path>'); rgb_img = img.convert('RGB'); rgb_img.save('<jpg_image_path>', 'JPEG'); print('图片转换成功')"
Replace <webp_image_path> with your WebP image path, and <jpg_image_path> with the JPG image path you want to save.
Notes
- The JPG format does not support transparency, so the transparent parts of WebP will be converted to a white background
- The quality of the converted image may change slightly
- Make sure the target path has write permission