πΈ
Want to generate a tiled pattern from an image? Here’s a simple Python app using Pillow and Gradio to let users resize an image and tile it as a grid. π
π What Youβll Need
- Pillow: For image processing
- Gradio: To create a simple web UI
π Step 1: Install Dependencies
Make sure you have the required libraries installed:
pip install pillow gradio
π Step 2: Create the Python Script
Hereβs the full code to create the tiling app:
from PIL import Image
import gradio as gr
def tile_image(img, resize_value, repeat_x, repeat_y):
# Resize input image
img = img.resize((resize_value, resize_value))
# Calculate new image dimensions
new_width = img.width * repeat_x
new_height = img.height * repeat_y
# Create blank canvas
new_img = Image.new('RGB', (new_width, new_height))
# Tile the image
for i in range(repeat_x):
for j in range(repeat_y):
new_img.paste(img, (i * img.width, j * img.height))
return new_img
# Gradio UI
iface = gr.Interface(
fn=tile_image,
inputs=[
gr.Image(type="pil", label="Upload Image"),
gr.Slider(50, 500, step=10, label="Resize Image"),
gr.Slider(1, 10, step=1, label="Horizontal Repeats"),
gr.Slider(1, 10, step=1, label="Vertical Repeats")
],
outputs=gr.Image(type="pil"),
title="Image Tiling Generator",
description="Upload an image, resize it, and set horizontal & vertical repeats to generate a tiled pattern.",
live=True
)
if __name__ == "__main__":
iface.launch()
π Step 3: Run the App
Run the script and Gradio will launch a web interface:
python image_tiling.py
You can now upload an image, choose the resize value, and set tiling parameters to generate a patterned output.
β¨ Enjoy creating beautiful image mosaics! β¨
Let me know if you have any questions! ππ