Skip to content

Instantly share code, notes, and snippets.

@WazedKhan
Created June 1, 2024 08:56
Show Gist options
  • Select an option

  • Save WazedKhan/9b87ab1c00a1aeb833ebaf1f3ff8c46e to your computer and use it in GitHub Desktop.

Select an option

Save WazedKhan/9b87ab1c00a1aeb833ebaf1f3ff8c46e to your computer and use it in GitHub Desktop.
def convert_image(input_image_path: str, output_image_path: str, output_format: str) -> None:
    try:
        # Open the input image
        with Image.open(input_image_path) as img:
            # Convert and save the image in the new format
            img.save(output_image_path, output_format)
        print(f"Image successfully converted to {output_format} and saved to {output_image_path}.")
    except Exception as e:
        print(f"An error occurred: {e}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment