Image Creator From Microsoft Bing (紙動物)


  1. 說明
    1. Script
    2. Animals

使用 Microsoft Bing Image Creator 所發展的紙動物,搭配 PIL 設計為 Photo Grids。

logo

說明

origami brown kangaroo with white body, detailed, white background

Script

from PIL import Image
import os
import glob
import uuid

images = glob.glob(os.path.join( "*.jfif"))
imageSize = 300

horizontal_photo_count = 3 
vertical_photo_count = 3

image_spacing = 2
spacing_color = (0,0,0)

canvas_width = horizontal_photo_count * imageSize + (horizontal_photo_count - 1) * image_spacing
canvas_height = vertical_photo_count * imageSize + (vertical_photo_count - 1) * image_spacing
canvas = Image.new('RGB', (canvas_width, canvas_height), spacing_color)

for y in range(horizontal_photo_count):
    for x in range(vertical_photo_count):
        image_filename = images.pop()
        img = Image.open(image_filename)
        img = img.resize((imageSize, imageSize), Image.ANTIALIAS)
        
        paste_x = x * (imageSize + image_spacing)
        paste_y = y * (imageSize + image_spacing)
        
        canvas.paste(img, (paste_y, paste_x))

canvas.save(f'Grids_{uuid.uuid1()}.jpg')

Animals