Compare commits
2 Commits
1dbec31687
...
be80ba6959
Author | SHA1 | Date |
---|---|---|
Bertrand Benjamin | be80ba6959 | |
Bertrand Benjamin | 6378ef5833 |
|
@ -17,24 +17,88 @@ photobook.set_fig_folder("textures")
|
||||||
photobook.one_centered("eugene.jpg", "one_centered default")
|
photobook.one_centered("eugene.jpg", "one_centered default")
|
||||||
photobook.one_centered("eugene.jpg", "")
|
photobook.one_centered("eugene.jpg", "")
|
||||||
photobook.one_centered(
|
photobook.one_centered(
|
||||||
"eugene.jpg",
|
"eugene.jpg", "one_centered text_ratio=1, img_ratio=1", text_ratio=1, img_ratio=1
|
||||||
"one_centered text_ratio=1, img_ratio=1",
|
|
||||||
text_ratio=1,
|
|
||||||
img_ratio=1
|
|
||||||
)
|
)
|
||||||
|
|
||||||
photobook.one_side("eugene.jpg", "one_side default")
|
photobook.one_side("eugene.jpg", "one_side default")
|
||||||
photobook.one_side(
|
photobook.one_side(
|
||||||
"eugene.jpg",
|
"eugene.jpg", "one_side text_ratio=1, img_ratio=1", text_ratio=1, img_ratio=1
|
||||||
"one_side text_ratio=1, img_ratio=1",
|
|
||||||
text_ratio=1,
|
|
||||||
img_ratio=1
|
|
||||||
)
|
)
|
||||||
photobook.one_side(
|
photobook.one_side(
|
||||||
"eugene.jpg",
|
"eugene.jpg", "one_side text_ratio=1, img_ratio=1", text_ratio=1, img_ratio=1
|
||||||
"one_side text_ratio=1, img_ratio=1",
|
)
|
||||||
text_ratio=1,
|
|
||||||
img_ratio=1
|
photobook.grid_row(
|
||||||
|
[
|
||||||
|
["eugene.jpg", "eugene.jpg", "eugene.jpg"],
|
||||||
|
["eugene.jpg", "grid_row default", "eugene.jpg"],
|
||||||
|
["eugene.jpg", "eugene.jpg", "eugene.jpg"],
|
||||||
|
],
|
||||||
|
)
|
||||||
|
photobook.grid_row(
|
||||||
|
[
|
||||||
|
["eugene.jpg", "eugene.jpg"],
|
||||||
|
[
|
||||||
|
"eugene.jpg",
|
||||||
|
"grid_row\nlayout = \n[[1, 2], [1, 1, 1], [2, 1]]",
|
||||||
|
"eugene.jpg",
|
||||||
|
],
|
||||||
|
["eugene.jpg", "eugene.jpg"],
|
||||||
|
],
|
||||||
|
layout=[[1, 2], [1, 1, 1], [2, 1]],
|
||||||
|
)
|
||||||
|
photobook.grid_row(
|
||||||
|
[
|
||||||
|
["eugene.jpg", "eugene.jpg", "eugene.jpg"],
|
||||||
|
["eugene.jpg", "grid_row ratios=[1, 3, 1]", "eugene.jpg"],
|
||||||
|
["eugene.jpg", "eugene.jpg", "eugene.jpg"],
|
||||||
|
],
|
||||||
|
ratios=[1, 3, 1],
|
||||||
|
)
|
||||||
|
photobook.grid_row(
|
||||||
|
[
|
||||||
|
["eugene.jpg"],
|
||||||
|
["eugene.jpg", "grid_row ratios=[1, 3, 1]", "eugene.jpg"],
|
||||||
|
["eugene.jpg", "eugene.jpg"],
|
||||||
|
],
|
||||||
|
ratios=[1, 3, 1],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
photobook.grid_column(
|
||||||
|
[
|
||||||
|
["eugene.jpg", "eugene.jpg", "eugene.jpg"],
|
||||||
|
["eugene.jpg", "grid_column default", "eugene.jpg"],
|
||||||
|
["eugene.jpg", "eugene.jpg", "eugene.jpg"],
|
||||||
|
],
|
||||||
|
)
|
||||||
|
photobook.grid_column(
|
||||||
|
[
|
||||||
|
["eugene.jpg", "eugene.jpg"],
|
||||||
|
[
|
||||||
|
"eugene.jpg",
|
||||||
|
"grid_column\nlayout = \n[[1, 2], [1, 1, 1], [2, 1]]",
|
||||||
|
"eugene.jpg",
|
||||||
|
],
|
||||||
|
["eugene.jpg", "eugene.jpg"],
|
||||||
|
],
|
||||||
|
layout=[[1, 2], [1, 1, 1], [2, 1]],
|
||||||
|
)
|
||||||
|
photobook.grid_column(
|
||||||
|
[
|
||||||
|
["eugene.jpg", "eugene.jpg", "eugene.jpg"],
|
||||||
|
["eugene.jpg", "grid_column ratios=[1, 3, 1]", "eugene.jpg"],
|
||||||
|
["eugene.jpg", "eugene.jpg", "eugene.jpg"],
|
||||||
|
],
|
||||||
|
ratios=[1, 3, 1],
|
||||||
|
)
|
||||||
|
photobook.grid_column(
|
||||||
|
[
|
||||||
|
["eugene.jpg"],
|
||||||
|
["eugene.jpg", "grid_column ratios=[1, 3, 1]", "eugene.jpg"],
|
||||||
|
["eugene.jpg", "eugene.jpg"],
|
||||||
|
],
|
||||||
|
ratios=[1, 3, 1],
|
||||||
)
|
)
|
||||||
|
|
||||||
photobook.output(dest)
|
photobook.output(dest)
|
||||||
|
|
|
@ -200,11 +200,12 @@ class Photobook(FPDF):
|
||||||
# self.image(img_dest, left, top, *win_dim)
|
# self.image(img_dest, left, top, *win_dim)
|
||||||
top += win_dim[1] + sep
|
top += win_dim[1] + sep
|
||||||
|
|
||||||
def grid_row(self, content, layout=[], with_margin=True, with_sep=True):
|
def grid_row(self, content, layout=[], ratios=[], with_margin=True, with_sep=True):
|
||||||
"""Custom layout define by rows
|
"""Custom layout define by rows
|
||||||
|
|
||||||
:param content: img or text to display in layout's cells
|
:param content: img or text to display in layout's cells
|
||||||
:param layout: cell layout with weight (need same shape than content)
|
:param layout: cell layout with weight (need same shape than content)
|
||||||
|
:param ratios: row's ratio
|
||||||
:param with_margin: Put margins around pictures
|
:param with_margin: Put margins around pictures
|
||||||
:param with_sep: Put separation between pictures
|
:param with_sep: Put separation between pictures
|
||||||
"""
|
"""
|
||||||
|
@ -235,26 +236,35 @@ class Photobook(FPDF):
|
||||||
f"Content and Layout need to have same number of columns at row {r}"
|
f"Content and Layout need to have same number of columns at row {r}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if ratios == []:
|
||||||
|
ratios = [1 for row in content]
|
||||||
|
else:
|
||||||
|
if len(content) != len(ratios):
|
||||||
|
raise ValueError("Content and ratios need to have same number of rows")
|
||||||
|
total_ratio = sum(ratios)
|
||||||
|
|
||||||
top = ori_top
|
top = ori_top
|
||||||
left = ori_left
|
left = ori_left
|
||||||
height_unit = (pg_size[1] - (len(layout) - 1) * sep) / len(layout)
|
height_unit = (pg_size[1] - (len(layout) - 1) * sep) / total_ratio
|
||||||
|
|
||||||
for (r, row) in enumerate(layout):
|
for (r, row) in enumerate(layout):
|
||||||
width_unit = (pg_size[0] - (len(row) - 1) * sep) / sum(row)
|
width_unit = (pg_size[0] - (len(row) - 1) * sep) / sum(row)
|
||||||
|
row_height = height_unit * ratios[r]
|
||||||
|
|
||||||
for (c, weight) in enumerate(row):
|
for (c, weight) in enumerate(row):
|
||||||
dim = (width_unit * weight, height_unit)
|
dim = (width_unit * weight, row_height)
|
||||||
self.append_content(content[r][c], left, top, *dim)
|
self.append_content(content[r][c], left, top, *dim)
|
||||||
|
|
||||||
left += dim[0] + sep
|
left += dim[0] + sep
|
||||||
top += height_unit + sep
|
top += row_height + sep
|
||||||
left = ori_left
|
left = ori_left
|
||||||
|
|
||||||
def grid_column(self, content, layout=[], with_margin=True, with_sep=True):
|
def grid_column(self, content, layout=[], ratios=[], with_margin=True, with_sep=True):
|
||||||
"""Custom layout define by column
|
"""Custom layout define by column
|
||||||
|
|
||||||
:param content: img or text to display in layout's cells
|
:param content: img or text to display in layout's cells
|
||||||
:param layout: cell layout with weight (need same shape than content)
|
:param layout: cell layout with weight (need same shape than content)
|
||||||
|
:param ratios: column's ratio
|
||||||
:param with_margin: Put margins around pictures
|
:param with_margin: Put margins around pictures
|
||||||
:param with_sep: Put separation between pictures
|
:param with_sep: Put separation between pictures
|
||||||
"""
|
"""
|
||||||
|
@ -287,19 +297,27 @@ class Photobook(FPDF):
|
||||||
f"Content and Layout need to have same number of columns at column {r}"
|
f"Content and Layout need to have same number of columns at column {r}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if ratios == []:
|
||||||
|
ratios = [1 for c in content]
|
||||||
|
else:
|
||||||
|
if len(content) != len(ratios):
|
||||||
|
raise ValueError("Content and ratios need to have same number of columns")
|
||||||
|
total_ratio = sum(ratios)
|
||||||
|
|
||||||
top = ori_top
|
top = ori_top
|
||||||
left = ori_left
|
left = ori_left
|
||||||
width_unit = (pg_size[0] - (len(layout) - 1) * sep) / len(layout)
|
width_unit = (pg_size[0] - (len(layout) - 1) * sep) / total_ratio
|
||||||
|
|
||||||
for (c, column) in enumerate(layout):
|
for (c, column) in enumerate(layout):
|
||||||
height_unit = (pg_size[1] - (len(column) - 1) * sep) / sum(column)
|
height_unit = (pg_size[1] - (len(column) - 1) * sep) / sum(column)
|
||||||
|
column_width = width_unit * ratios[c]
|
||||||
|
|
||||||
for (r, weight) in enumerate(column):
|
for (r, weight) in enumerate(column):
|
||||||
dim = (width_unit, height_unit * weight)
|
dim = (column_width, height_unit * weight)
|
||||||
self.append_content(content[c][r], left, top, *dim)
|
self.append_content(content[c][r], left, top, *dim)
|
||||||
|
|
||||||
top += dim[1] + sep
|
top += dim[1] + sep
|
||||||
left += width_unit + sep
|
left += column_width + sep
|
||||||
top = ori_top
|
top = ori_top
|
||||||
|
|
||||||
def append_content(self, content, left, top, width, height):
|
def append_content(self, content, left, top, width, height):
|
||||||
|
|
Loading…
Reference in New Issue