{"id":9,"date":"2025-02-01T21:57:32","date_gmt":"2025-02-01T21:57:32","guid":{"rendered":"https:\/\/photokurs.com\/wordpress\/?p=9"},"modified":"2025-02-01T21:57:32","modified_gmt":"2025-02-01T21:57:32","slug":"create-an-image-tiling-app-with-python-gradio","status":"publish","type":"post","link":"https:\/\/photokurs.com\/wordpress\/index.php\/2025\/02\/01\/create-an-image-tiling-app-with-python-gradio\/","title":{"rendered":"Create an Image Tiling App with Python &amp; Gradio"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">\ud83d\udcf8 <\/h1>\n\n\n\n<p>Want to generate a tiled pattern from an image? Here&#8217;s a simple Python app using <strong>Pillow<\/strong> and <strong>Gradio<\/strong> to let users resize an image and tile it as a grid. \ud83d\ude80<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udee0 What You\u2019ll Need<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Pillow<\/strong>: For image processing<\/li>\n\n\n\n<li><strong>Gradio<\/strong>: To create a simple web UI<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udccc Step 1: Install Dependencies<\/h2>\n\n\n\n<p>Make sure you have the required libraries installed:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install pillow gradio<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udccc Step 2: Create the Python Script<\/h2>\n\n\n\n<p>Here\u2019s the full code to create the tiling app:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from PIL import Image\nimport gradio as gr\n\ndef tile_image(img, resize_value, repeat_x, repeat_y):\n    # Resize input image\n    img = img.resize((resize_value, resize_value))\n    \n    # Calculate new image dimensions\n    new_width = img.width * repeat_x\n    new_height = img.height * repeat_y\n    \n    # Create blank canvas\n    new_img = Image.new('RGB', (new_width, new_height))\n    \n    # Tile the image\n    for i in range(repeat_x):\n        for j in range(repeat_y):\n            new_img.paste(img, (i * img.width, j * img.height))\n    \n    return new_img\n\n# Gradio UI\niface = gr.Interface(\n    fn=tile_image,\n    inputs=&#91;\n        gr.Image(type=\"pil\", label=\"Upload Image\"),\n        gr.Slider(50, 500, step=10, label=\"Resize Image\"),\n        gr.Slider(1, 10, step=1, label=\"Horizontal Repeats\"),\n        gr.Slider(1, 10, step=1, label=\"Vertical Repeats\")\n    ],\n    outputs=gr.Image(type=\"pil\"),\n    title=\"Image Tiling Generator\",\n    description=\"Upload an image, resize it, and set horizontal &amp; vertical repeats to generate a tiled pattern.\",\n    live=True\n)\n\nif __name__ == \"__main__\":\n    iface.launch()\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udccc Step 3: Run the App<\/h2>\n\n\n\n<p>Run the script and Gradio will launch a web interface:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python image_tiling.py<\/code><\/pre>\n\n\n\n<p>You can now upload an image, choose the resize value, and set tiling parameters to generate a patterned output.<\/p>\n\n\n\n<p>\u2728 <strong>Enjoy creating beautiful image mosaics!<\/strong> \u2728<\/p>\n\n\n\n<p>Let me know if you have any questions! \ud83d\ude0a\ud83d\ude80<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\ud83d\udcf8 Want to generate a tiled pattern from an image? Here&#8217;s a simple Python app using Pillow and Gradio to let users resize an image and tile it as a grid. \ud83d\ude80 \ud83d\udee0 What You\u2019ll Need \ud83d\udccc Step 1: Install Dependencies Make sure you have the required libraries installed: \ud83d\udccc Step 2: Create the Python [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-9","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/photokurs.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/9","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/photokurs.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/photokurs.com\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/photokurs.com\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/photokurs.com\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=9"}],"version-history":[{"count":1,"href":"https:\/\/photokurs.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/9\/revisions"}],"predecessor-version":[{"id":10,"href":"https:\/\/photokurs.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/9\/revisions\/10"}],"wp:attachment":[{"href":"https:\/\/photokurs.com\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=9"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/photokurs.com\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=9"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/photokurs.com\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=9"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}