from PIL import Image, ImageDraw, ImageFont import io from google.colab import files
print("Please upload your image (use a small size for faster processing):") uploaded = files.upload()
image_path = list(uploaded.keys())[0] image = Image.open(io.BytesIO(uploaded[image_path]))
print("Resizing the image for optimization...") image = image.resize((500, 500)) # Optimized for mobile processing (500x500)
def add_text_behind_image(image, text, position=(50, 50)): # Create a transparent overlay overlay = Image.new("RGBA", image.size, (255, 255, 255, 0)) draw = ImageDraw.Draw(overlay)
# Use the default font for compatibility
font = ImageFont.load_default()
# Draw text with transparency
draw.text(position, text, fill=(255, 255, 255, 150), font=font)
# Merge the original image with the overlay
return Image.alpha_composite(image.convert("RGBA"), overlay)
text_to_add = input("Enter the text to add behind the image: ")
print("Processing the image...") processed_image = add_text_behind_image(image, text_to_add, position=(100, 100))
print("Displaying the processed image...") processed_image.show()
output_path = "processed_image.png" processed_image.save(output_path) print("Image processed and saved. Downloading now...") files.download(output_path)