Feat: add part of text in one_centered

This commit is contained in:
Bertrand Benjamin 2022-07-05 07:07:08 +02:00
parent ed2c61fd42
commit 81cc461746

View File

@ -109,6 +109,7 @@ class Photobook(FPDF):
self,
img,
text="",
part_of_text=6,
):
"""Display the picture centered with text below"""
self.add_page()
@ -116,7 +117,7 @@ class Photobook(FPDF):
if text == "":
text_size = (0, 0)
else:
text_size = (self.epw, (self.eph - self.sep) / 6 - self.sep)
text_size = (self.epw, (self.eph - self.sep) / part_of_text - self.sep)
img_size = (self.epw, self.eph - text_size[1])
img_dest = self.img_process(img, img_size)
@ -301,82 +302,3 @@ class Photobook(FPDF):
self.cell(width, height, content, align="C", border=1)
if __name__ == "__main__":
name = "annee3"
pagesize = (250, 200)
src_fig = Path("./fig/")
output = Path("./build/")
dest = output / (name + ".pdf")
out_fig = output / "fig"
photobook = Photobook(name, pdf_size=pagesize)
photobook.set_font("Arial", "B", 20)
photobook.set_auto_page_break(False)
photobook.rows(["chronologie/annee3/1-DD/DD-01.jpg"])
photobook.rows(
["chronologie/annee3/1-DD/DD-01.jpg", "chronologie/annee3/1-DD/DD-02.jpg"]
)
photobook.rows(
["chronologie/annee3/1-DD/DD-01.jpg", "chronologie/annee3/1-DD/DD-02.jpg"],
with_margin=False,
)
photobook.rows(
["chronologie/annee3/1-DD/DD-01.jpg", "chronologie/annee3/1-DD/DD-02.jpg"],
with_sep=False,
)
photobook.rows(
["chronologie/annee3/1-DD/DD-01.jpg", "chronologie/annee3/1-DD/DD-02.jpg"],
with_margin=False,
with_sep=False,
)
photobook.rows(
[
"chronologie/annee3/1-DD/DD-01.jpg",
"Tralalala",
"chronologie/annee3/1-DD/DD-02.jpg",
"chronologie/annee3/1-DD/DD-02.jpg",
]
)
photobook.grid_row(
[
["chronologie/annee3/1-DD/DD-01.jpg", "chronologie/annee3/1-DD/DD-02.jpg"],
["Coucou c'est moi!!", "chronologie/annee3/1-DD/DD-04.jpg"],
],
[[1, 2], [3, 1]],
)
photobook.grid_row(
[
["chronologie/annee3/1-DD/DD-01.jpg", "chronologie/annee3/1-DD/DD-02.jpg"],
["Coucou c'est moi!! \ncjfkldsq", "chronologie/annee3/1-DD/DD-04.jpg"],
],
[[1, 2], [3, 1]],
)
photobook.grid_row(
[
["chronologie/annee3/1-DD/DD-01.jpg", "chronologie/annee3/1-DD/DD-02.jpg"],
["chronologie/annee3/1-DD/DD-03.jpg", "chronologie/annee3/1-DD/DD-04.jpg"],
],
[[1, 2], [3, 1]],
)
photobook.set_top_margin(40)
photobook.grid_row(
[
["chronologie/annee3/1-DD/DD-01.jpg", "chronologie/annee3/1-DD/DD-02.jpg"],
["chronologie/annee3/1-DD/DD-03.jpg", "chronologie/annee3/1-DD/DD-04.jpg"],
],
[[1, 2], [3, 1]],
)
photobook.restore_margin()
photobook.grid_row(
[
["chronologie/annee3/1-DD/DD-01.jpg", "chronologie/annee3/1-DD/DD-02.jpg"],
["chronologie/annee3/1-DD/DD-03.jpg", "chronologie/annee3/1-DD/DD-04.jpg"],
],
[[1, 1], [1, 1]],
with_margin=False,
with_sep=False,
)
photobook.output(dest)