Feat: add use of ration for on_side

This commit is contained in:
Bertrand Benjamin 2022-07-06 06:29:54 +02:00
parent 58edb87ebc
commit 1dbec31687
2 changed files with 38 additions and 9 deletions

View File

@ -16,7 +16,25 @@ photobook.set_auto_page_break(False)
photobook.set_fig_folder("textures") 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("eugene.jpg", "one_centered text_ratio=1, img_ratio=1", text_ratio=1, img_ratio=1) photobook.one_centered(
"eugene.jpg",
"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 text_ratio=1, img_ratio=1",
text_ratio=1,
img_ratio=1
)
photobook.one_side(
"eugene.jpg",
"one_side text_ratio=1, img_ratio=1",
text_ratio=1,
img_ratio=1
)
photobook.output(dest) photobook.output(dest)

View File

@ -116,7 +116,10 @@ class Photobook(FPDF):
self.add_page() self.add_page()
total_ratio = img_ratio + text_ratio total_ratio = img_ratio + text_ratio
text_size = (self.epw, (self.eph - self.sep) * text_ratio / total_ratio - self.sep) text_size = (
self.epw,
(self.eph - self.sep) * text_ratio / total_ratio - self.sep,
)
img_size = (self.epw, self.eph - text_size[1]) img_size = (self.epw, self.eph - text_size[1])
img_dest = self.img_process(img, img_size) img_dest = self.img_process(img, img_size)
@ -130,22 +133,32 @@ class Photobook(FPDF):
else: else:
self.cell(text_size[0], text_size[1] - self.sep, text, align="C", border=1) self.cell(text_size[0], text_size[1] - self.sep, text, align="C", border=1)
def one_side(self, img, txt=""): def one_side(
self,
img,
txt="",
img_ratio=5,
text_ratio=1,
):
"""Display the image on the outside of the page """Display the image on the outside of the page
along with text on the other side along with text on the other side
""" """
self.add_page() self.add_page()
p_no = self.page_no() p_no = self.page_no()
win_dim = (self.size[0] * 2 / 3, self.size[1])
total_ratio = img_ratio + text_ratio
win_dim = (self.size[0] * img_ratio / total_ratio, self.size[1])
img_dest = self.img_process(img, win_dim) img_dest = self.img_process(img, win_dim)
if p_no % 2 == 1: if p_no % 2 == 1:
self.set_xy(win_dim[0], self.size[1] / 2) self.set_xy(win_dim[0], self.size[1] / 2)
self.multi_cell(self.size[0] / 3, self.font_size, txt, align="C") self.multi_cell(self.size[0] * text_ratio/ total_ratio, self.font_size, txt, align="C")
self.image(img_dest, 0, 0, *win_dim) self.image(img_dest, 0, 0, *win_dim)
else: else:
self.set_xy(0, self.size[1] / 2) self.set_xy(0, self.size[1] / 2)
self.multi_cell(self.size[0] / 3, self.font_size, txt, align="C") self.multi_cell(self.size[0] * text_ratio / total_ratio, self.font_size, txt, align="C")
self.image(img_dest, self.size[0] / 3, 0, *win_dim) self.image(img_dest, self.size[0] * text_ratio / total_ratio, 0, *win_dim)
def one_side_nocut(self, img, txt=""): def one_side_nocut(self, img, txt=""):
"""Display the image on the outside of the page without resize it""" """Display the image on the outside of the page without resize it"""
@ -299,5 +312,3 @@ class Photobook(FPDF):
self.multi_cell(width, self.font_size, content, align="J", border=1) self.multi_cell(width, self.font_size, content, align="J", border=1)
else: else:
self.cell(width, height, content, align="C", border=1) self.cell(width, height, content, align="C", border=1)