SD Is EATING Your Drive! 5x SMALLER filesize, SAME QUALITY! Compress AI images & More! (Webp Images)

3 min read 2 hours ago
Published on Oct 26, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

This tutorial will guide you through compressing AI-generated images to significantly reduce file sizes while maintaining quality. By using the WEBP format and specific tools, you can save storage space on your drive, especially if you've been working with large AI images in Stable Diffusion.

Step 1: Check Image Saving Settings

  • Ensure that the "Save all images" option is enabled in your AI image generation tool. This setting helps manage file generation efficiently.

Step 2: Understand Image File Sizes

  • Be aware that many AI-generated images, especially when upscaled, can take up a lot of disk space. This is crucial to address before you end up with a full drive.

Step 3: Choose the Right Image Format

  • Use PNG instead of JPEG/JPG for generating images when possible. PNGs typically offer better quality for images with text or sharp edges.

Step 4: Convert to WEBP Format

  • WEBP is a modern image format that provides superior compression. By converting your images to WEBP, you can achieve significantly smaller file sizes without sacrificing quality.

Step 5: Install Required Tools

  1. Install cwebp:

    • Download the cwebp tool from the Google Developers page.
    • Follow the installation instructions based on your operating system.
  2. Install ExifTool:

    • Download ExifTool from exiftool.org.
    • This tool will help retain important metadata during the image conversion process.

Step 6: Prepare for Python Scripting

  • Get Python installed on your system if you haven't already. You will use it to run a script for converting images in bulk.

Step 7: Use the Conversion Script

  • Download the Auto AI image convert script from GitHub.
  • Open the script and modify any paths as necessary to point to your images.
  • Run the script to convert your existing PNG and JPG/JPEG images to WEBP format, ensuring you keep important generation data.
# Example code snippet for using the script
import os
from PIL import Image

# Convert function
def convert_images_to_webp(source_folder):
    for filename in os.listdir(source_folder):
        if filename.endswith('.png') or filename.endswith('.jpg'):
            img = Image.open(os.path.join(source_folder, filename))
            img.save(os.path.join(source_folder, filename.replace('.png', '.webp').replace('.jpg', '.webp')), 'webp')

# Specify your source folder here
convert_images_to_webp('path/to/your/images')

Step 8: Mass Convert Existing Images

  • Use cwebp to convert existing images in bulk. Here’s a command to get you started:
cwebp -q 80 input.png -o output.webp
  • Replace input.png with your image file and output.webp with the desired output filename.

Step 9: Save Space for New Images

  • After converting your existing images, you will have freed up significant space. This will allow you to generate new images without worrying about running out of storage.

Conclusion

By following these steps, you can effectively compress your AI-generated images, saving up to 5 times the original file size while keeping the same quality. Installing the necessary tools and using the appropriate scripts will streamline the conversion process, making it easier to manage your images in the future. Consider generating future images in WEBP format to maintain efficiency from the start.