{"id":25265,"date":"2021-03-29T11:55:16","date_gmt":"2021-03-29T11:55:16","guid":{"rendered":"https:\/\/holypython.com\/?page_id=25265"},"modified":"2022-12-10T00:18:40","modified_gmt":"2022-12-10T00:18:40","slug":"creating-photo-collages","status":"publish","type":"page","link":"https:\/\/holypython.com\/python-pil-tutorial\/creating-photo-collages\/","title":{"rendered":"Creating Photo Collages"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-page\" data-elementor-id=\"25265\" class=\"elementor elementor-25265\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-38819ef elementor-reverse-mobile elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"38819ef\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-50 elementor-top-column elementor-element elementor-element-98d652e\" data-id=\"98d652e\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-a65a2b4 elementor-widget elementor-widget-text-editor\" data-id=\"a65a2b4\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<div>\u00a0 <a style=\"background-color: #ffffff;\" href=\"https:\/\/holypython.com\/python-pil-tutorial\/\">&lt;&lt;&lt; PIL Tutorials<\/a><\/div><hr \/><ol><li><a href=\"https:\/\/holypython.com\/python-pil-tutorial\/how-to-create-a-new-image-with-pil\/\"><span style=\"font-weight: bold;\">Create<\/span> a new image<\/a><\/li><li><a href=\"https:\/\/holypython.com\/python-pil-tutorial\/how-to-open-show-and-save-images-in-python-pil\/\"><b>Open<\/b>, <b>Show<\/b> &amp; <b>Save<\/b> images (PIL)<\/a><\/li><li><a href=\"https:\/\/holypython.com\/python-pil-tutorial\/pasting-merging-blending-images-with-python-pil\/\"><b>Paste<\/b>, <b>Merge<\/b>, <b>Blend<\/b> images (PIL)<\/a><\/li><li><a href=\"https:\/\/holypython.com\/python-pil-tutorial\/how-to-draw-shapes-on-images-python-ultimate-guide\/\">How to <b>Draw<\/b> shapes images (PIL)<\/a><\/li><li><a href=\"https:\/\/holypython.com\/python-pil-tutorial\/how-to-crop-images-with-python-pil\/\">How to <b>Crop <\/b>an image (PIL)<\/a><\/li><li><a href=\"https:\/\/holypython.com\/python-pil-tutorial\/how-to-add-text-to-images-in-python-via-pil-library\/\">How to <b>Add Text<\/b> to images (PIL)<\/a><\/li><li><a href=\"https:\/\/holypython.com\/python-pil-tutorial\/how-to-add-frames-to-images-in-python-via-pil-library\/\">How to <b>Add Frames<\/b> to images (PIL)<\/a><\/li><li><a href=\"https:\/\/holypython.com\/python-pil-tutorial\/how-to-resize-an-image-and-get-size-in-python-pil\/\">How to <b>Resize <\/b>an image (PIL)<\/a><\/li><li><a href=\"https:\/\/holypython.com\/python-pil-tutorial\/how-to-adjust-brightness-contrast-sharpness-and-saturation-of-images-in-python-pil\/\"><b>Brightness<\/b>, <b>Contrast<\/b>, <b>Saturation\u00a0<\/b><\/a><\/li><li><a href=\"https:\/\/holypython.com\/python-pil-tutorial\/how-to-convert-an-image-to-black-white-in-python-pil\/\">Convert image to <span style=\"font-weight: bold;\">Grayscale | B&amp;W<\/span><\/a><span style=\"font-weight: bold;\"><br \/><\/span><\/li><li><a href=\"https:\/\/holypython.com\/python-pil-tutorial\/creating-photo-collages\/\">Create <span style=\"font-weight: bold;\">Photo Collages<\/span><\/a><\/li><li><a href=\"https:\/\/holypython.com\/python-pil-tutorial\/color-modes-explained-for-digital-image-processing-in-python-pil\/\">Digital Image <b>Color Modes<\/b>\u00a0<\/a><\/li><li><a href=\"https:\/\/holypython.com\/digital-image-basics-with-pil-library-in-python\/\">Digital Image <span style=\"font-weight: bold;\">Basics<\/span><\/a><\/li><li><a href=\"https:\/\/holypython.com\/image-manipulation-with-python-pil\/\"><b>Image Manipulation<\/b> w\/ PIL<\/a><\/li><li><a href=\"https:\/\/holypython.com\/how-to-batch-resize-multiple-images-in-python-via-pil-library\/\"><span style=\"font-weight: bold;\">Batch Resize<\/span> Multiple Images (PIL)<\/a><\/li><li><a href=\"https:\/\/holypython.com\/how-to-watermark-images-w-python-pil\/\"><span style=\"font-weight: bold;\">Watermarking<\/span> Images<\/a><\/li><li><a href=\"https:\/\/holypython.com\/python-code-to-show-the-difference-between-2-images\/\"><b>Difference Between 2<\/b> Images (PIL)<\/a><\/li><\/ol>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t<div class=\"elementor-column elementor-col-50 elementor-top-column elementor-element elementor-element-820bd33\" data-id=\"820bd33\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-inner-section elementor-element elementor-element-2eacc4c elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"2eacc4c\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-50 elementor-inner-column elementor-element elementor-element-1d7add4\" data-id=\"1d7add4\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-c9dba6c elementor-widget elementor-widget-heading\" data-id=\"c9dba6c\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h1 class=\"elementor-heading-title elementor-size-default\">Creating Photo Collages<\/h1>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t<div class=\"elementor-column elementor-col-50 elementor-inner-column elementor-element elementor-element-3a3ccc8\" data-id=\"3a3ccc8\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-57329d4 elementor-widget elementor-widget-raven-image\" data-id=\"57329d4\" data-element_type=\"widget\" data-widget_type=\"raven-image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"raven-image\">\r\n\t\t\t\t\t<figure class=\"wp-caption\">\r\n\t\t\r\n\t\t\r\n\t\t<img fetchpriority=\"high\" decoding=\"async\" width=\"500\" height=\"500\" src=\"https:\/\/holypython.com\/wp-content\/uploads\/2021\/03\/300_2-Custom.png\" class=\"attachment-full size-full wp-image-25320\" alt=\"\" srcset=\"https:\/\/holypython.com\/wp-content\/uploads\/2021\/03\/300_2-Custom.png 500w, https:\/\/holypython.com\/wp-content\/uploads\/2021\/03\/300_2-Custom-300x300.png 300w, https:\/\/holypython.com\/wp-content\/uploads\/2021\/03\/300_2-Custom-150x150.png 150w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/>\t\t\t<figcaption class=\"widget-image-caption wp-caption-text\">Image collage created with PIL<\/figcaption>\r\n\t\t\t\t\t\t<\/figure>\r\n\t\t\t\t\t<\/div>\r\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<div class=\"elementor-element elementor-element-98a498b elementor-widget elementor-widget-text-editor\" data-id=\"98a498b\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Contents<\/p>\n<ul>\n<li><a href=\"#intro\">Introduction<\/a>\n<ol>\n<li><a href=\"#new_image\">Create a New Image (Grid Layer)<\/a><\/li>\n<li><a href=\"#image_pieces\">Image Pieces<\/a><\/li>\n<li><a href=\"#paste_method\">Paste Method<\/a><\/li>\n<li><a href=\"#example1\">Example 1: Image Effects<\/a><\/li>\n<li><a href=\"#example2\">Example 2: Color Hue Layers<\/a><\/li>\n<li><a href=\"#example3\">Example 3: Image Batch<\/a><\/li>\n<li><a href=\"#save_collage\">How to save an Image Collage<\/a><\/li>\n<\/ol>\n<\/li>\n<li><a style=\"background-color: #ffffff;\" href=\"#summary\">Summary<\/a><\/li>\n<\/ul>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<section class=\"elementor-section elementor-inner-section elementor-element elementor-element-eeece35 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"eeece35\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-inner-column elementor-element elementor-element-883b749\" data-id=\"883b749\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-b3f3750 elementor-widget elementor-widget-menu-anchor\" data-id=\"b3f3750\" data-element_type=\"widget\" data-widget_type=\"menu-anchor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-menu-anchor\" id=\"intro\"><\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-49a0273 elementor-widget elementor-widget-heading\" data-id=\"49a0273\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Introduction<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-4cbd9b7 elementor-widget elementor-widget-text-editor\" data-id=\"4cbd9b7\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Collages are compositions created using different components of visual objects.\u00a0This form of creation can be used in business, art, newspapers, blogs and even music.<\/p><p>In this Python tutorial we will demonstrate how to create image collages using Python.<\/p><p>An image collage can easily be created using Python&#8217;s PIL module by creating a large enough &#8220;<b>new image<\/b>&#8221; which will be used as the collage layer or grid and by taking advantage of Python Loops to paste new images to the grid through iteration. We will explain each step below as clearly as possible.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-inner-section elementor-element elementor-element-e61fb19 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"e61fb19\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-inner-column elementor-element elementor-element-ed2d7cf\" data-id=\"ed2d7cf\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-d67b7db elementor-widget elementor-widget-menu-anchor\" data-id=\"d67b7db\" data-element_type=\"widget\" data-widget_type=\"menu-anchor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-menu-anchor\" id=\"new_image\"><\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-668c9eb elementor-widget elementor-widget-heading\" data-id=\"668c9eb\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">1- Creating a New Image<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-3c265ee elementor-widget elementor-widget-text-editor\" data-id=\"3c265ee\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>You can create a new image using PIL&#8217;s new method as below. It&#8217;s important to pay attention to color modes here as they can significantly impact the image manipulations that can be done on them as well as image saving options.<\/p><p>Here is a new image example with .new() method. First parameter is the <b>color mode<\/b> of the image while the second parameter in a tuple is the <b>dimensions<\/b> of the image.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-34e6b46 elementor-widget elementor-widget-html\" data-id=\"34e6b46\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>new = Image.new(\"RGBA\", (2000,2000))\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-7526824 elementor-widget elementor-widget-text-editor\" data-id=\"7526824\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Here we are creating an image in RGBA mode with 2000 pixel width and 2000 pixel height. For an extensive knowledge regarding <b>color modes<\/b> you can visit this tutorial:<\/p><ul><li><a href=\"https:\/\/holypython.com\/python-pil-tutorial\/color-modes-explained-for-digital-image-processing-in-python-pil\/\">Python Digital Image Color Modes<\/a><\/li><\/ul>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-inner-section elementor-element elementor-element-0241d94 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"0241d94\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-inner-column elementor-element elementor-element-d5478fe\" data-id=\"d5478fe\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-80b30b3 elementor-widget elementor-widget-menu-anchor\" data-id=\"80b30b3\" data-element_type=\"widget\" data-widget_type=\"menu-anchor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-menu-anchor\" id=\"image_pieces\"><\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-e335f33 elementor-widget elementor-widget-heading\" data-id=\"e335f33\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">2- Preparing Individual Images<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-bd28d0d elementor-widget elementor-widget-text-editor\" data-id=\"bd28d0d\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Whether it&#8217;s gathering images or creating effects we are going to have to prepare individual pieces that can be laid out together in a collage or image grid.<\/p><p>This can be achieved through iterating a single image to create multiple versions of it or we can also use multiple images.<\/p><p>For example check out this incomplete Python code:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-a503ec2 elementor-widget elementor-widget-html\" data-id=\"a503ec2\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"PYTHON\"><code>c=1\nfor i in range(0,2000,500):\n    for j in range(0,2000,500):\n        new_img = filter.enhance(c)\n        c+=0.02\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-cab8c6c elementor-widget elementor-widget-text-editor\" data-id=\"cab8c6c\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Here we are creating a variable named c for creating different effects which is incremented inside the for loop at each iteration.<\/p><p>We also have nested loops this will allow us to iterate image positions on the grid with steps of 500 pixels. During the first iteration of the first loop, inner loop will create the first row.<\/p><p>Once first iteration of the first loop is complete second row will be created and so on until the end of the collage.<\/p><p>Also you can tell there will be 4 iterations each for both outer and inner loops since range function is used with steps of 500 from 0 to 2000.<\/p><p>You can also see that new_img file will have a new version at each iteration due to changing c parameter and effect applied based on that.<\/p><p>So if we just add an operation to past these new images to the bigger collage inside the iteration we will have a collage in our hands.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-inner-section elementor-element elementor-element-73799a7 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"73799a7\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-inner-column elementor-element elementor-element-92184fe\" data-id=\"92184fe\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-0e32ed3 elementor-widget elementor-widget-menu-anchor\" data-id=\"0e32ed3\" data-element_type=\"widget\" data-widget_type=\"menu-anchor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-menu-anchor\" id=\"paste_method\"><\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-43dbaf4 elementor-widget elementor-widget-heading\" data-id=\"43dbaf4\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">3- Paste Method<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-0346614 elementor-widget elementor-widget-text-editor\" data-id=\"0346614\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>PIL has a useful method called <b>paste()<\/b> which can be used to paste an image on another image.<\/p><p>In the example below, using <b>paste<\/b> method we are pasting a smaller image named new_img to a new image we created using <b>Image.new<\/b> and named <b>collage.<\/b><\/p><p>Our collage is a new image which consists of 2000 by 2000 pixels. Our piece of image is an actual photo we are opening using <b>Image.open<\/b>\u00a0and is then resized to 500 by 500 pixels to fit the larger collage platform.<\/p><p>Finally, you can see paste is exercised with a coordination of (0,0) which will place it in the upper left corner of the collage. Let&#8217;s see the results.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-1bc90da elementor-widget elementor-widget-html\" data-id=\"1bc90da\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>from PIL import Image, ImageEnhance\r\n\r\nnew = Image.new(\"RGBA\", (1000,1000))\r\n\r\nimg = Image.open(\"Desktop\/300.jpg\")\r\nimg = img.resize((500,500))\r\nnew.paste(img, (0,0))\r\nnew.paste(img, (500,500))\r\n\r\nnew.show()\r\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-1afb64b elementor-widget elementor-widget-image\" data-id=\"1afb64b\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t<figure class=\"wp-caption\">\n\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" width=\"250\" height=\"250\" src=\"https:\/\/holypython.com\/wp-content\/uploads\/2021\/03\/300_1-Custom.png\" class=\"attachment-full size-full wp-image-25313\" alt=\"\" srcset=\"https:\/\/holypython.com\/wp-content\/uploads\/2021\/03\/300_1-Custom.png 250w, https:\/\/holypython.com\/wp-content\/uploads\/2021\/03\/300_1-Custom-150x150.png 150w\" sizes=\"(max-width: 250px) 100vw, 250px\" \/>\t\t\t\t\t\t\t\t\t\t\t<figcaption class=\"widget-image-caption wp-caption-text\">PIL 2x2 Image Grid<\/figcaption>\n\t\t\t\t\t\t\t\t\t\t<\/figure>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-e1557e7 elementor-widget elementor-widget-text-editor\" data-id=\"e1557e7\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>We won&#8217;t be able to save an RGBA image with Alpha transparency channel as a jpg file but it can be saved as a png.<\/p><p>This is a nice exercise for warming up let&#8217;s create a larger grid and spread the images on it to create an image collage.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-4b2c155 elementor-widget elementor-widget-html\" data-id=\"4b2c155\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>from PIL import Image, ImageEnhance\r\n\r\nnew = Image.new(\"RGBA\", (2000,2000))\r\n\r\nimg = Image.open(\"Desktop\/300.jpg\")\r\nimg = img.resize((500,500))\r\n\r\nnew.paste(img, (0,0))\r\nnew.paste(img, (1000,0))\r\nnew.paste(img, (500,500))\r\nnew.paste(img, (1500,500))\r\nnew.paste(img, (0,1000))\r\nnew.paste(img, (1000,1000))\r\nnew.paste(img, (500,1500))\r\nnew.paste(img, (1500,1500))\r\n\r\nnew.show()\r\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8ca75a8 elementor-widget elementor-widget-image\" data-id=\"8ca75a8\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t<figure class=\"wp-caption\">\n\t\t\t\t\t\t\t\t\t\t<img fetchpriority=\"high\" decoding=\"async\" width=\"500\" height=\"500\" src=\"https:\/\/holypython.com\/wp-content\/uploads\/2021\/03\/300_2-Custom.png\" class=\"attachment-full size-full wp-image-25320\" alt=\"\" srcset=\"https:\/\/holypython.com\/wp-content\/uploads\/2021\/03\/300_2-Custom.png 500w, https:\/\/holypython.com\/wp-content\/uploads\/2021\/03\/300_2-Custom-300x300.png 300w, https:\/\/holypython.com\/wp-content\/uploads\/2021\/03\/300_2-Custom-150x150.png 150w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/>\t\t\t\t\t\t\t\t\t\t\t<figcaption class=\"widget-image-caption wp-caption-text\">PIL 2x2 Image Grid<\/figcaption>\n\t\t\t\t\t\t\t\t\t\t<\/figure>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c221d83 elementor-widget elementor-widget-text-editor\" data-id=\"c221d83\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Great. Now we are able to:<\/p><ol><li>Create a new image using PIL<\/li><li>Open an existing image and resize it<\/li><li>Paste the existing image on the large grid or layout image to create image collages<\/li><\/ol><p>Now let&#8217;s attempt to perform some fancy tricks to create more sophisticated and give some ideas for future work.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-inner-section elementor-element elementor-element-8315404 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"8315404\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-inner-column elementor-element elementor-element-4943013\" data-id=\"4943013\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-437bf51 elementor-widget elementor-widget-menu-anchor\" data-id=\"437bf51\" data-element_type=\"widget\" data-widget_type=\"menu-anchor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-menu-anchor\" id=\"example1\"><\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-9eeb872 elementor-widget elementor-widget-heading\" data-id=\"9eeb872\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">4- Example 1: Image Effects<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-e2b18b5 elementor-widget elementor-widget-text-editor\" data-id=\"e2b18b5\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Using the same logic introduced above we can create an iteration with for loop and apply new effects to the images at each iteration.<\/p><p>In this example, we are opening an image named 300.jpg, resizing it to 500X500 pixels, creating a brightness filter and applying it using variable c at each iteration.<\/p><p>We are also creating a new image with the applied effect at each iteration and pasting it on the collage.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-715a501 elementor-widget elementor-widget-html\" data-id=\"715a501\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>newfrom PIL import Image, ImageEnhance\r\ncollage = Image.new(\"RGBA\", (2000,1000))\r\n\r\nimg = Image.open(\"Desktop\/300.jpg\")\r\nimg = img.resize((500,500))\r\n\r\nfilter = ImageEnhance.Brightness(img)\r\n\r\nc=0.7\r\nfor i in range(0,2000,500):\r\n    for j in range(0,2000,500):\r\n        new_img = filter.enhance(c)\r\n        collage.paste(new_img, (j,i))\r\n        c+=0.1\r\n        print(c)\r\nnew.show()\r\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-301d0a6 elementor-widget elementor-widget-image\" data-id=\"301d0a6\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t<figure class=\"wp-caption\">\n\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" width=\"700\" height=\"350\" src=\"https:\/\/holypython.com\/wp-content\/uploads\/2021\/03\/300_3-Custom.jpg\" class=\"attachment-full size-full wp-image-25354\" alt=\"\" srcset=\"https:\/\/holypython.com\/wp-content\/uploads\/2021\/03\/300_3-Custom.jpg 700w, https:\/\/holypython.com\/wp-content\/uploads\/2021\/03\/300_3-Custom-300x150.jpg 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/>\t\t\t\t\t\t\t\t\t\t\t<figcaption class=\"widget-image-caption wp-caption-text\">Image Collage with different brightness levels<\/figcaption>\n\t\t\t\t\t\t\t\t\t\t<\/figure>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-1828bea elementor-widget elementor-widget-text-editor\" data-id=\"1828bea\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Great. This collage could be useful for a professional photographer or social media manager while trying to decide on the exact photo enhancement values.<\/p><p>We can do the same kind of operation with many other image effects available via PIL library. You can see a detailed tutorial about these effects in the link below:<\/p><ul><li><a href=\"https:\/\/holypython.com\/python-pil-tutorial\/how-to-adjust-brightness-contrast-sharpness-and-saturation-of-images-in-python-pil\/\">Python Image Effects via PIL<\/a><\/li><\/ul><p>Let&#8217;s showcase a few other examples created with the same logic of iterating using for loops. All we have to do is replace the filter and adjust the c enhancement parameter accordingly.<\/p><p>Please note some filters may require negative c values to create the same effects as below. You can see a detailed breakdown of the effects in the Image Effects Tutorial shared above.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-516a4ec elementor-widget elementor-widget-image\" data-id=\"516a4ec\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t<figure class=\"wp-caption\">\n\t\t\t\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"675\" height=\"450\" src=\"https:\/\/holypython.com\/wp-content\/uploads\/2021\/03\/300_4-Custom.jpg\" class=\"attachment-full size-full wp-image-25355\" alt=\"\" srcset=\"https:\/\/holypython.com\/wp-content\/uploads\/2021\/03\/300_4-Custom.jpg 675w, https:\/\/holypython.com\/wp-content\/uploads\/2021\/03\/300_4-Custom-300x200.jpg 300w\" sizes=\"(max-width: 675px) 100vw, 675px\" \/>\t\t\t\t\t\t\t\t\t\t\t<figcaption class=\"widget-image-caption wp-caption-text\">Image Collage with different color levels<\/figcaption>\n\t\t\t\t\t\t\t\t\t\t<\/figure>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-9cfb758 elementor-widget elementor-widget-html\" data-id=\"9cfb758\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>filter = ImageEnhance.Color(img)\r\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-6851369 elementor-widget elementor-widget-image\" data-id=\"6851369\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t<figure class=\"wp-caption\">\n\t\t\t\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"675\" height=\"450\" src=\"https:\/\/holypython.com\/wp-content\/uploads\/2021\/03\/300_5-Custom.jpg\" class=\"attachment-full size-full wp-image-25359\" alt=\"\" srcset=\"https:\/\/holypython.com\/wp-content\/uploads\/2021\/03\/300_5-Custom.jpg 675w, https:\/\/holypython.com\/wp-content\/uploads\/2021\/03\/300_5-Custom-300x200.jpg 300w\" sizes=\"(max-width: 675px) 100vw, 675px\" \/>\t\t\t\t\t\t\t\t\t\t\t<figcaption class=\"widget-image-caption wp-caption-text\">Image Collage with different color levels<\/figcaption>\n\t\t\t\t\t\t\t\t\t\t<\/figure>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-7950ece elementor-widget elementor-widget-html\" data-id=\"7950ece\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>filter = ImageEnhance.Contrast(img)\r\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-030924a elementor-widget elementor-widget-image\" data-id=\"030924a\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t<figure class=\"wp-caption\">\n\t\t\t\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"675\" height=\"450\" src=\"https:\/\/holypython.com\/wp-content\/uploads\/2021\/03\/300_6-Custom.jpg\" class=\"attachment-full size-full wp-image-25360\" alt=\"\" srcset=\"https:\/\/holypython.com\/wp-content\/uploads\/2021\/03\/300_6-Custom.jpg 675w, https:\/\/holypython.com\/wp-content\/uploads\/2021\/03\/300_6-Custom-300x200.jpg 300w\" sizes=\"(max-width: 675px) 100vw, 675px\" \/>\t\t\t\t\t\t\t\t\t\t\t<figcaption class=\"widget-image-caption wp-caption-text\">Image Collage with different sharpness levels<\/figcaption>\n\t\t\t\t\t\t\t\t\t\t<\/figure>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-3822b32 elementor-widget elementor-widget-html\" data-id=\"3822b32\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>filter = ImageEnhance.Sharpness(img)\r\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-inner-section elementor-element elementor-element-00217c5 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"00217c5\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-inner-column elementor-element elementor-element-2b59c38\" data-id=\"2b59c38\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-35daaa3 elementor-widget elementor-widget-menu-anchor\" data-id=\"35daaa3\" data-element_type=\"widget\" data-widget_type=\"menu-anchor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-menu-anchor\" id=\"example2\"><\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-698886e elementor-widget elementor-widget-heading\" data-id=\"698886e\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">5- Example 2: Color Hue Layers<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-67e3ca7 elementor-widget elementor-widget-text-editor\" data-id=\"67e3ca7\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Another option is to create a semi-transparent layer with a certain color and then blend it with the image at hand to create a hue effect (or color tint). We can then iterate again and create fun collages with different images. Let&#8217;s try to implement it.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-3e6b412 elementor-widget elementor-widget-html\" data-id=\"3e6b412\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>from PIL import Image, ImageDraw\r\n\r\ncollage = Image.new(\"RGBA\", (1500,1500), color=(255,255,255,255))\r\nphoto = Image.open(\"Desktop\/1200.jpg\").convert(\"RGBA\")\r\nphoto = new_img.resize((500,500))\r\n\r\nfor i in range(0,1500,500):\r\n    rr=00\r\n    bb=0\r\n    gg=150\r\n    for j in range(0,1500,500):\r\n        \r\n        hue = Image.new(\"RGBA\", (photo.size), color=(rr,gg,bb))\r\n        new_img = Image.blend(photo,hue,0.5)\r\n        rr+=50\r\n        bb+=50\r\n        gg-=50\r\n        \r\n        collage.paste(new_img, (i,j))\r\ncollage.show()\r\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-1427171 elementor-widget elementor-widget-text-editor\" data-id=\"1427171\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>In this Python code we are creating a collage, opening an image with variable:\u00a0<b>photo<\/b>. Then inside the inner for loop we are creating a new image and manipulate its RGB channels via <b>color<\/b> parameter.<\/p><p>Additionally, we are creating a new image called <b>new_img<\/b> by blending <b>hue<\/b> layer and the original photo we opened (<b>photo<\/b>) 50\/50. This blending task is done using handy\u00a0<b>Image.blend()<\/b> method with alpha value of 0.5.<\/p><p>The results are interesting.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c2f33d0 elementor-widget elementor-widget-image\" data-id=\"c2f33d0\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t<figure class=\"wp-caption\">\n\t\t\t\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"675\" height=\"675\" src=\"https:\/\/holypython.com\/wp-content\/uploads\/2021\/03\/1200_1-Custom.jpg\" class=\"attachment-full size-full wp-image-25370\" alt=\"\" srcset=\"https:\/\/holypython.com\/wp-content\/uploads\/2021\/03\/1200_1-Custom.jpg 675w, https:\/\/holypython.com\/wp-content\/uploads\/2021\/03\/1200_1-Custom-300x300.jpg 300w, https:\/\/holypython.com\/wp-content\/uploads\/2021\/03\/1200_1-Custom-150x150.jpg 150w, https:\/\/holypython.com\/wp-content\/uploads\/2021\/03\/1200_1-Custom-500x500.jpg 500w\" sizes=\"(max-width: 675px) 100vw, 675px\" \/>\t\t\t\t\t\t\t\t\t\t\t<figcaption class=\"widget-image-caption wp-caption-text\">Image Collage with hue effect<\/figcaption>\n\t\t\t\t\t\t\t\t\t\t<\/figure>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8652351 elementor-widget elementor-widget-text-editor\" data-id=\"8652351\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Since gg value is initially 150 and rr and bb are 0, and then this green image is blended with the photo by a factor of 50% transparency, image collage starts with a greenish image.<\/p><p>Throughout the iteration green channel is decremented by 50 at each iteration while red and blue channels are incremented by 50. The result is decreasing green tint at each photo and increasing red and blue tints.<\/p><p>There is no hue effect in PIL but this low level digital image manipulation is an example to the creative outcomes that can be achieved with Python programming.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-inner-section elementor-element elementor-element-70549f7 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"70549f7\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-inner-column elementor-element elementor-element-ce45bfd\" data-id=\"ce45bfd\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-0007657 elementor-widget elementor-widget-menu-anchor\" data-id=\"0007657\" data-element_type=\"widget\" data-widget_type=\"menu-anchor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-menu-anchor\" id=\"example3\"><\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-de9e4e2 elementor-widget elementor-widget-heading\" data-id=\"de9e4e2\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">6- Example 3: Image Batch<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-5c9ead0 elementor-widget elementor-widget-text-editor\" data-id=\"5c9ead0\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Another idea is to iterate through different images and create a collage with them. This can simply be achieved by opening a different image at each iteration and pasting it to the collage.<\/p><p>In this example we will use a sequence of file names in Desktop folder and concatenate them. Image file names can also be read automatically from inside a folder using <b>listdir()<\/b> method from <b>os<\/b> library.<\/p><p>For a similar example created with <b>listdir()<\/b> method you can visit this tutorial:<\/p><ul><li><a href=\"https:\/\/holypython.com\/how-to-batch-resize-multiple-images-in-python-via-pil-library\/\">How to batch resize multiple images in Python<\/a><\/li><\/ul><div>And here is the Python code:<\/div>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c59b626 elementor-widget elementor-widget-html\" data-id=\"c59b626\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>from PIL import Image, ImageDraw\r\n\r\ncollage = Image.new(\"RGBA\", (1500,1500), color=(255,255,255,255))\r\nlst = [100, 200, 300, 400, 500, 600, 700, 800, 900]\r\n\r\nc=0\r\nfor i in range(0,1500,500):\r\n    for j in range(0,1500,500):\r\n        file = \"Desktop\/\"+str(lst[c])+\".jpg\"\r\n        photo = Image.open(file).convert(\"RGBA\")\r\n        photo = photo.resize((500,500))        \r\n        \r\n        collage.paste(photo, (i,j))\r\n        c+=1\r\ncollage.show()\r\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-1d4033b elementor-widget elementor-widget-image\" data-id=\"1d4033b\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t<figure class=\"wp-caption\">\n\t\t\t\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"675\" height=\"675\" src=\"https:\/\/holypython.com\/wp-content\/uploads\/2021\/03\/1700_5-Custom.jpg\" class=\"attachment-full size-full wp-image-25383\" alt=\"\" srcset=\"https:\/\/holypython.com\/wp-content\/uploads\/2021\/03\/1700_5-Custom.jpg 675w, https:\/\/holypython.com\/wp-content\/uploads\/2021\/03\/1700_5-Custom-300x300.jpg 300w, https:\/\/holypython.com\/wp-content\/uploads\/2021\/03\/1700_5-Custom-150x150.jpg 150w, https:\/\/holypython.com\/wp-content\/uploads\/2021\/03\/1700_5-Custom-500x500.jpg 500w\" sizes=\"(max-width: 675px) 100vw, 675px\" \/>\t\t\t\t\t\t\t\t\t\t\t<figcaption class=\"widget-image-caption wp-caption-text\">Image Collage with different images<\/figcaption>\n\t\t\t\t\t\t\t\t\t\t<\/figure>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-inner-section elementor-element elementor-element-151effb elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"151effb\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-inner-column elementor-element elementor-element-5fd0642\" data-id=\"5fd0642\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-5a8d582 elementor-widget elementor-widget-menu-anchor\" data-id=\"5a8d582\" data-element_type=\"widget\" data-widget_type=\"menu-anchor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-menu-anchor\" id=\"save_collage\"><\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-39a7787 elementor-widget elementor-widget-heading\" data-id=\"39a7787\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">8- How to Save Image Collages<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-4258ae4 elementor-widget elementor-widget-text-editor\" data-id=\"4258ae4\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Since we have an image object at hand saving a collage is not very different than saving individual images in Python. You can see the code example below. Also, we have a dedicated PIL tutorial which you are welcome to visit for more details:<\/p><ul><li><a href=\"https:\/\/holypython.com\/python-pil-tutorial\/how-to-open-show-and-save-images-in-python-pil\/\">How to Save Images with Python<\/a><\/li><\/ul><p>If you are interested in different color modes and their interaction with file types such as jpg, png, bmp and gif then you can visit this tutorial as well:<\/p><ul><li><a href=\"https:\/\/holypython.com\/python-pil-tutorial\/color-modes-explained-for-digital-image-processing-in-python-pil\/\">Python Digital Image Color Modes<\/a><\/li><\/ul><p>And also you can learn a lot about the fundamentals of digital images from this one:<\/p><ul><li><a href=\"https:\/\/holypython.com\/digital-image-basics-with-pil-library-in-python\/\">Digital Image Basics<\/a><\/li><\/ul>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-5fee324 elementor-widget elementor-widget-html\" data-id=\"5fee324\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>collage.save(\"Desktop\/collage.png\")\r\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-inner-section elementor-element elementor-element-c27a064 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"c27a064\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-inner-column elementor-element elementor-element-590b7a4\" data-id=\"590b7a4\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-acd0f14 elementor-widget elementor-widget-menu-anchor\" data-id=\"acd0f14\" data-element_type=\"widget\" data-widget_type=\"menu-anchor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-menu-anchor\" id=\"summary\"><\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-461dc3b elementor-widget elementor-widget-heading\" data-id=\"461dc3b\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Summary<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-f4b53bd elementor-widget elementor-widget-text-editor\" data-id=\"f4b53bd\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>In this <a style=\"background-color: #ffffff;\" href=\"https:\/\/holypython.com\/\">Python Tutorial<\/a> we learned how to create image collages using a variety of different techniques.<\/p><ul><li><a href=\"#example1\">Ex1<\/a>: Image Collage with different effects<\/li><li><a href=\"#example2\">Ex2<\/a>: Image Collage with different hues (color tints)<\/li><li><a href=\"#example3\">Ex3<\/a>: Image Collage with different images<\/li><\/ul><p>We took advantage of opening images, creating new images, saving images and used namely:\u00a0<b>new<\/b>, <b>open<\/b>, <b>resize<\/b>, <b>paste <\/b>and <b>blend<\/b> methods.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>\u00a0 &lt;&lt;&lt; PIL Tutorials Create a new image Open, Show &amp; Save images (PIL) Paste, Merge, Blend images (PIL) How to Draw shapes images (PIL) How to Crop an image (PIL) How to Add Text to images (PIL) How to Add Frames to images (PIL) How to Resize an image (PIL) Brightness, Contrast, Saturation\u00a0 Convert [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":16180,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"full-width.php","meta":{"_acf_changed":false,"footnotes":""},"class_list":["post-25265","page","type-page","status-publish","hentry"],"acf":[],"_links":{"self":[{"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/pages\/25265","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/comments?post=25265"}],"version-history":[{"count":0,"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/pages\/25265\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/pages\/16180"}],"wp:attachment":[{"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/media?parent=25265"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}