Untitled

 avatar
unknown
plain_text
2 years ago
1.2 kB
3
Indexable
from PIL import Image

def apply_filter(image, filter_type):
    if filter_type == "grayscale":
        return image.convert("L")
    elif filter_type == "blur":
        return image.filter(ImageFilter.BLUR)
    elif filter_type == "rotate":
        return image.rotate(45)
    else:
        return image

def main():
    # Open the image
    image_path = "path_to_your_image.jpg"  # Replace with the path to your image file
    image = Image.open(image_path)
    
    # Display the available filter options
    print("Available filters:")
    print("- grayscale")
    print("- blur")
    print("- rotate")
    
    # Prompt the user for the filter to apply
    filter_type = input("Enter the filter type: ")
    
    # Apply the chosen filter
    filtered_image = apply_filter(image, filter_type)
    
    # Show the original and filtered images
    image.show(title="Original Image")
    filtered_image.show(title="Filtered Image")
    
    # Save the filtered image
    save_path = "path_to_save_filtered_image.jpg"  # Replace with the desired save path
    filtered_image.save(save_path)
    
if __name__ == "__main__":
    main()

Editor is loading...