Your Own Webp Converter

By Narasimha

What it Does:

  • Turns your JPG and PNG images into WebP images (good for websites).
  • Makes image file sizes smaller so websites load faster.
  • Keeps your subfolder organization.
  • With simple GUI

What You Need:

  1. Python installed on your computer.
  2. To install one extra thing called "Pillow".

How to Install Pillow (One Time Only):

  1. Open your computer's Terminal or Command Prompt.
  2. Type **pip install Pillow ****and press Enter.

How to Use:

  1. Save the below Script: Save the code as webp_converter.py.
  2. Prepare Images: Put your JPG/PNG images into an Input Folder. You can make subfolders inside (like featured, gallery) - the script will copy that structure. Likewise, create an Output Folder where webp images get stored.
  3. Run Script: Open Terminal/Command Prompt, go to where you saved the script (cd path/to/script), and type python webp_converter.py or alternatively you can use VSCode for the same.
  4. Use the Pop-up Window:
    • Click "Browse..." next to "Input Folder" and choose the folder with your images.
    • Click "Browse..." next to "Output Location" and choose where you want the results saved.
    • Leave "Strip Metadata" checked (usually best).
    • Click "Start Conversion".
  5. Wait: Watch the status bar at the bottom. It will say "Finished" when done.

What You Get (in your chosen Output Location):

  • WebP_Output folder: Contains your new .webp images, organized like your input folder. Use these for your website!
  • Error_Files folder: If the script couldn't read an original image, it moves the bad original file here.
  • error.log file: A text file with details about the last run (errors, how much smaller files got). It gets replaced each time you run the script.

Good to Know:

  • It aims for high quality (Quality 85) but uses "lossy" compression to save space (like JPGs do).
  • It works hard to make files small (Method 6), so it might take a little time for many images.
  • If your PNGs had clear backgrounds, they will have white backgrounds in the WebP version.

WebP Converter - Code