Jun-06-2018, 11:06 AM
Hello,
I'm trying to write a python script using Pillow :
count files ( png images ) number create an image for every 64 images. example: if the folder containing 640 images ( or any other number ), I will get 10 images as a thumbnail of 64 images/outputimage
any idea?
I started by this step :
example: out1.pan will contain 0.png to 63.png
Thank you
I'm trying to write a python script using Pillow :
count files ( png images ) number create an image for every 64 images. example: if the folder containing 640 images ( or any other number ), I will get 10 images as a thumbnail of 64 images/outputimage
any idea?
I started by this step :
import os import os.path from PIL import Image image_dir = os.path.abspath("path_to_png_folder") # list all files in directory files = os.listdir(image_dir) # get all PNGs png_files = filter(lambda x: x.endswith(".png"), files) # make file paths absolute image_files = map(lambda x: os.sep.join([image_dir, x]), png_files) print (image_files) n_files = len(image_files) # print (n_files) target_img = None n_targets = 0 collage_saved = False for n in range(n_files): img = Image.open(image_files[n]) img.thumbnail((100, 100)) if n % 64 == 0: # create an empty image for a collage target_img = Image.new("RGB", (800, 800)) n_targets += 1 collage_saved = False # paste the image at the correct position i = int(n / 8) j = n % 8 target_img.paste(img, (100*i, 100*j)) if (n + 1) % 64 == 0 and target_img is not None: # save a finished 8x8 collage target_img.save("{0:04}.png".format(n_targets)) collage_saved = True # save the last collage if not collage_saved: target_img.save("{0:04}.png".format(n_targets))I got 10 images, the first one contain 8x8 images, the others are empty ( black ). also, since my png files are a sequence from 0.png to 640.png; have any idea how to let the paste operation take images by order.
example: out1.pan will contain 0.png to 63.png
Thank you