mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Arrange rendered images in a grid 🏢
This commit is contained in:
parent
580655a3bf
commit
40c879e3c0
@ -1,6 +1,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
|
import math
|
||||||
from PIL import Image, ImageDraw, ImageFont
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
|
|
||||||
|
|
||||||
@ -42,6 +43,7 @@ class MultiboxRenderer:
|
|||||||
images = []
|
images = []
|
||||||
|
|
||||||
layout_count = int(self.content[0])
|
layout_count = int(self.content[0])
|
||||||
|
horizontal = math.ceil(math.sqrt(layout_count))
|
||||||
start = 1
|
start = 1
|
||||||
|
|
||||||
for _ in range(layout_count):
|
for _ in range(layout_count):
|
||||||
@ -57,15 +59,35 @@ class MultiboxRenderer:
|
|||||||
images.append(renderer.export())
|
images.append(renderer.export())
|
||||||
start += action_count
|
start += action_count
|
||||||
|
|
||||||
width = max(image.width for image in images) + 20
|
i = 0
|
||||||
height = sum(image.height for image in images) + 10 * (len(images) + 1)
|
x = 10
|
||||||
|
y = 10
|
||||||
|
width = 10
|
||||||
|
row_height = 0
|
||||||
|
|
||||||
|
positions = []
|
||||||
|
|
||||||
|
for image in images:
|
||||||
|
positions.append((x, y))
|
||||||
|
|
||||||
|
x += 10 + image.width
|
||||||
|
row_height = max(row_height, image.height)
|
||||||
|
|
||||||
|
i += 1
|
||||||
|
if i >= horizontal:
|
||||||
|
width = max(width, x)
|
||||||
|
x = 10
|
||||||
|
y += 10 + row_height
|
||||||
|
i = 0
|
||||||
|
|
||||||
|
height = y
|
||||||
|
if i != 0:
|
||||||
|
height += 10 + row_height
|
||||||
|
|
||||||
self.combined = Image.new('RGBA', (width, height))
|
self.combined = Image.new('RGBA', (width, height))
|
||||||
|
|
||||||
cursor = 10
|
for (position, image) in zip(positions, images):
|
||||||
for image in images:
|
self.combined.paste(image, position)
|
||||||
self.combined.paste(image, (10, cursor))
|
|
||||||
cursor += 10 + image.height
|
|
||||||
|
|
||||||
def export(self):
|
def export(self):
|
||||||
return self.combined
|
return self.combined
|
||||||
|
Loading…
x
Reference in New Issue
Block a user