Skip to content

Commit

Permalink
feat: use webp
Browse files Browse the repository at this point in the history
Signed-off-by: 117503445 <[email protected]>
  • Loading branch information
117503445 committed Sep 20, 2023
1 parent e7e7f32 commit 28ab391
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/flow_pdf/flow_pdf/worker/json_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@
)
from typing import Optional

def convert_img_to_webp(file_img: Path) -> Path:
'''
convert image to webp format, and return the path of the converted image
'''
file_webp = file_img.parent / f"{file_img.stem}.webp"
with Image.open(file_img) as img:
img.save(file_webp, "webp")
# file_img.unlink()
return file_webp

@dataclass
class DocInParams(DocInputParams):
most_common_font: str
Expand Down Expand Up @@ -279,13 +289,13 @@ def make_groups(line: MLine) -> list[SpanGroup]:
)
else:
page.get_pixmap(clip=r_tuple, dpi=576).save(file_shot) # type: ignore

chidren.append(
{
"type": "shot",
"path": f"./assets/{file_shot.name}",
}
)
file_shot = convert_img_to_webp(file_shot)
chidren.append(
{
"type": "shot",
"path": f"./assets/{file_shot.name}",
}
)
column_block_elements.append(p)

shots = page_in.shot_rects[column_index]
Expand All @@ -300,6 +310,8 @@ def make_groups(line: MLine) -> list[SpanGroup]:
save_shot_pixmap(shot, file_shot)
# crop_image(file_shot)


file_shot = convert_img_to_webp(file_shot)
shot_counter += 1

column_block_elements.append(
Expand Down

0 comments on commit 28ab391

Please sign in to comment.