Use Python to Auto-Enhance All Photos in a Folder

import os
from PIL import Image, ImageEnhance

# Set input and output folders
input_folder = 'input_photos'
output_folder = 'output_photos'

# Set enhancement factors
color_factor = 1.2
contrast_factor = 1.2
brightness_factor = 1.2
vibrancy_factor = 1.2

# Create output folder if it doesn't exist
if not os.path.exists(output_folder):
    os.makedirs(output_folder)

def enhance_image(image_path):
    # Open image
    image = Image.open(image_path)

    # Enhance color
    enhancer = ImageEnhance.Color(image)
    image = enhancer.enhance(color_factor)

    # Enhance contrast
    enhancer = ImageEnhance.Contrast(image)
    image = enhancer.enhance(contrast_factor)

    # Enhance brightness
    enhancer = ImageEnhance.Brightness(image)
    image = enhancer.enhance(brightness_factor)

    # Enhance vibrancy (saturation)
    enhancer = ImageEnhance.Color(image)
    image = enhancer.enhance(vibrancy_factor)

    return image

# Iterate through all images in the input folder
for filename in os.listdir(input_folder):
    # Check if file is an image
    if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.tiff', '.bmp', '.gif')):
        print(f"Processing {filename}")
        
        # Enhance image
        input_path = os.path.join(input_folder, filename)
        enhanced_image = enhance_image(input_path)

        # Save enhanced image to output folder
        output_path = os.path.join(output_folder, filename)
        enhanced_image.save(output_path)

print("All images processed.")

Comments

Popular posts from this blog

Unveiling the Power of PowerShell Regions: A Comprehensive Guide

PowerShell Script to Remotely Update Firmware on Brother Printers Microsoft

PowerShell Script to Reset Permissions on all Documents in a Document Library in SharePoint Online.