Best Of
syntax line number test
import requests
from tkinter import Tk, filedialog
from PIL import Image
import io
import os
def download_image():
# Ask the user for the URL
url = input("Enter the image URL: ").strip()
try:
# Request the image
response = requests.get(url, stream=True)
response.raise_for_status()
except Exception as e:
print(f"Error downloading image: {e}")
return
# Load the image into Pillow
try:
image = Image.open(io.BytesIO(response.content))
except Exception as e:
print(f"Error processing image: {e}")
return
# Hide the root tkinter window
root = Tk()
root.withdraw()
# Open Save As dialog
save_path = filedialog.asksaveasfilename(
defaultextension=".png",
filetypes=[("PNG files", "*.png")],
title="Save Image As"
)
if not save_path:
print("Save cancelled.")
return
# Ensure the output is PNG
try:
image.save(save_path, "PNG")
print(f"Image saved as {save_path}")
except Exception as e:
print(f"Error saving image: {e}")
if name == "main":
download_image()
1 ·
Rock n Roll
It's been a long time since I rock and rolled
It's been a long time since I did the stroll
Ooh let me get it back, let me get it back
Let me get it back, baby, where I come from
RPlant
4 ·
Re: What's your preferred brand for smartphone cases
I like KWMobile cases. Lots of colour selection.
Bugs
1 ·
What's your preferred brand for smartphone cases
Otterbox is known for protection, but what about style?
stimpy
1 ·

