Commit 4de8810c authored by kernel.h@qq.com's avatar kernel.h@qq.com

update

parent 84a87899
...@@ -132,7 +132,7 @@ def pdf_command(pdf, model, method): ...@@ -132,7 +132,7 @@ def pdf_command(pdf, model, method):
local_image_dir, _ = prepare_env() local_image_dir, _ = prepare_env()
local_image_rw = DiskReaderWriter(local_image_dir) local_image_rw = DiskReaderWriter(local_image_dir)
parse = get_pdf_parse_method(method) parse = get_pdf_parse_method(method)
parse(pdf_data, jso["doc_layout_result"], local_image_rw, is_debug=True) parse(pdf_data, jso, local_image_rw, is_debug=True)
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -17,7 +17,7 @@ def read_config(): ...@@ -17,7 +17,7 @@ def read_config():
config_file = os.path.join(home_dir, "magic-pdf.json") config_file = os.path.join(home_dir, "magic-pdf.json")
if not os.path.exists(config_file): if not os.path.exists(config_file):
raise Exception("magic-pdf.json not found") raise Exception(f"{config_file} not found")
with open(config_file, "r") as f: with open(config_file, "r") as f:
config = json.load(f) config = json.load(f)
......
from magic_pdf.io import AbsReaderWriter
from magic_pdf.libs.commons import fitz from magic_pdf.libs.commons import fitz
from loguru import logger from loguru import logger
from magic_pdf.libs.commons import join_path from magic_pdf.libs.commons import join_path
from magic_pdf.libs.hash_utils import compute_sha256 from magic_pdf.libs.hash_utils import compute_sha256
def cut_image(bbox: tuple, page_num: int, page: fitz.Page, return_path, imageWriter): def cut_image(bbox: tuple, page_num: int, page: fitz.Page, return_path, imageWriter:AbsReaderWriter):
""" """
从第page_num页的page中,根据bbox进行裁剪出一张jpg图片,返回图片路径 从第page_num页的page中,根据bbox进行裁剪出一张jpg图片,返回图片路径
save_path:需要同时支持s3和本地, 图片存放在save_path下,文件名是: {page_num}_{bbox[0]}_{bbox[1]}_{bbox[2]}_{bbox[3]}.jpg , bbox内数字取整。 save_path:需要同时支持s3和本地, 图片存放在save_path下,文件名是: {page_num}_{bbox[0]}_{bbox[1]}_{bbox[2]}_{bbox[3]}.jpg , bbox内数字取整。
...@@ -28,6 +29,7 @@ def cut_image(bbox: tuple, page_num: int, page: fitz.Page, return_path, imageWri ...@@ -28,6 +29,7 @@ def cut_image(bbox: tuple, page_num: int, page: fitz.Page, return_path, imageWri
byte_data = pix.tobytes(output='jpeg', jpg_quality=95) byte_data = pix.tobytes(output='jpeg', jpg_quality=95)
imageWriter.write(byte_data, path=img_hash256_path, mode="binary")
imageWriter.write(content=byte_data, path=img_hash256_path, mode="binary") imageWriter.write(content=byte_data, path=img_hash256_path, mode="binary")
return img_hash256_path return img_hash256_path
...@@ -73,4 +75,4 @@ def save_images_by_bboxes(page_num: int, page: fitz.Page, pdf_bytes_md5: str, ...@@ -73,4 +75,4 @@ def save_images_by_bboxes(page_num: int, page: fitz.Page, pdf_bytes_md5: str,
image_path = cut_image(bbox, page_num, page, return_path("tables"), imageWriter) image_path = cut_image(bbox, page_num, page, return_path("tables"), imageWriter)
table_info.append({"bbox": bbox, "image_path": image_path}) table_info.append({"bbox": bbox, "image_path": image_path})
return image_info, image_backup_info, table_info, inline_eq_info, interline_eq_info return image_info, image_backup_info, table_info, inline_eq_info, interline_eq_info
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment