Resize and convert images to base64 and webp
Resize and convert images to base64 and webp
Convert images to webp and base64
Small python script to resize and convert images to webp and provide base64 data in a .txt file
Overview
The Base64 Convert App is a Python script that automates the process of converting images to Base64 format and resizing them. It’s particularly useful for embedding images directly into Markdown files for Jekyll-based websites. The app also generates WebP versions of the images for better compression and quality.
Features
- Converts images in the
imagesfolder to Base64 format. - Saves the Base64 string to a
.txtfile with the same name as the image. - Resizes the image to 250x160 pixels.
- Converts the resized image to WebP format.
- Saves the WebP image with a
_converted.webpsuffix.
How to Use
- Setup: Place the
convert.pyscript in the same directory as yourimagesfolder. - Batch File: Double-click the provided
.batfile. This will set up a Python virtual environment, install required packages, and run theconvert.pyscript. - Output: After running, you’ll find a
.txtfile containing the Base64 string and a_converted.webpimage in theimagesfolder for each image processed.
Requirements
- Python 3.x
- Pillow library (automatically installed by the
.batfile)
Notes
- The
.batfile will check if a virtual environment already exists. If it does, it will simply activate it and run the script. - Detailed logs will be displayed in the CMD window, including any errors.
Linux
Use the convert.sh
give it execute permissions (chmod +x convert.sh), and then you can run it with ./convert.sh
Find it here on github Base64
This post is licensed under CC BY 4.0 by the author.
