Если вдруг кто-то захочет сшить простыню как в >>20330
#!/usr/bin/env python
import Image
import sys
padding_x = 16
padding_y = 8
width = 800
if len(sys.argv) < 3:
print 'Usage: {0} <images> <output>'.format(sys.argv[0])
sys.exit(-1)
class Row(object):
pass
rows = []
row = None
for filename in sys.argv[1:-1]:
image = Image.open(filename)
if row is None or row.width + image.size[0] + padding_x > width:
row = Row()
rows.append(row)
row.images = []
row.width = padding_x
row.height = 0
row.images.append(image)
row.width += image.size[0] + padding_x
row.height = max(row.height, image.size[1])
height = padding_y
for row in rows:
height += row.height + padding_y
collage = Image.new('RGB', (width, height), (255, 255, 255))
pos_y = padding_y
for row in rows:
pos_x = (width - row.width) / 2 + padding_x
for image in row.images:
collage.paste(image, (pos_x, pos_y + (row.height - image.size[1])/2))
pos_x += image.size[0] + padding_x
pos_y += row.height + padding_y
collage.save(sys.argv[-1])