Python Forum
Combine images using Pillow and Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Combine images using Pillow and Python
#3
I will split the script in 3 different steps:
  • A function that from a list of images create a thumbnail
  • List all the image files
  • Split in groups of a desired size a list of images

For the 1st point you can do something like:
def create_collage(files, out):
    # You can add a check to guarantee that the list of images is not bigger than 64...
    target_img = Image.new("RGB", (800, 800))
    for k, png in enumerate(files):
        row, col = divmod(k, 8)
        img = Image.open(png)
        img.thumbnail((100, 100))
        target_img.paste(img, (100*row, 100*col))

    target_img.save(out)
To list all the images in a directory you can use the glob module that will filter them by extension for you:
import glob
files = glob.glob('./*.png')
And to group every 64 elements might be:
groups = [files[k:k+64] for k in range(0, len(files), 64)]
Reply


Messages In This Thread
Combine images using Pillow and Python - by GMA - Jun-05-2018, 04:26 PM
RE: Combine images using Pillow and Python - by killerrex - Jun-06-2018, 11:41 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how to read multispectral images on python noorasim 0 1,821 Feb-28-2021, 03:54 PM
Last Post: noorasim
  How do I insert images in Python using gspread (or any other package)? ivansing23 0 2,307 Jul-27-2020, 01:26 PM
Last Post: ivansing23
  My journey with attaching file instead of images using Python numbnumb54 1 1,817 Jul-24-2020, 02:37 AM
Last Post: scidam
  A more efficient way of comparing two images in a python vukan 0 2,051 Mar-17-2020, 11:39 AM
Last Post: vukan
  how to compare two different size images in python and find corresponding pixel value squidsirymchenry 1 4,634 Feb-03-2020, 06:48 AM
Last Post: michael1789
  How to get first 5 images form the document using Python BeautifulSoup sarath_unrelax 0 1,670 Dec-19-2019, 07:13 AM
Last Post: sarath_unrelax
  Compare two images with Python is possible? Delemir78 3 4,870 Dec-17-2019, 09:03 PM
Last Post: Larz60+
  Python Pillow I_Am_Groot 1 2,684 Oct-13-2018, 07:28 AM
Last Post: j.crater
  [split] Python Pillow - Photo Manipulation keegan_010 1 3,009 Oct-11-2018, 09:57 AM
Last Post: Larz60+
  Python Pillow - Photo Manipulation keegan_010 2 2,953 Oct-11-2018, 03:49 AM
Last Post: keegan_010

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020