浏览代码

fix(pre_proc): prevent errors when imageWriter is None

- Updated cut_image.py to check for NoneType imageWriter
- Prevents AttributeError when imageWriter is not provided
myhloli 11 月之前
父节点
当前提交
7f8dc353b0
共有 1 个文件被更改,包括 2 次插入2 次删除
  1. 2 2
      magic_pdf/pre_proc/cut_image.py

+ 2 - 2
magic_pdf/pre_proc/cut_image.py

@@ -12,12 +12,12 @@ def ocr_cut_image_and_table(spans, page, page_id, pdf_bytes_md5, imageWriter):
     for span in spans:
         span_type = span['type']
         if span_type == ContentType.Image:
-            if not check_img_bbox(span['bbox']):
+            if not check_img_bbox(span['bbox']) or not imageWriter:
                 continue
             span['image_path'] = cut_image(span['bbox'], page_id, page, return_path=return_path('images'),
                                            imageWriter=imageWriter)
         elif span_type == ContentType.Table:
-            if not check_img_bbox(span['bbox']):
+            if not check_img_bbox(span['bbox']) or not imageWriter:
                 continue
             span['image_path'] = cut_image(span['bbox'], page_id, page, return_path=return_path('tables'),
                                            imageWriter=imageWriter)