[Bug]: PDF images saved with save_images_locally=True come back with an empty src in result.media

オープン 初心者向け
#2,469 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
backend

調査の方向性

PDFプロセッサで PDFContentScrapingStrategy.scrap() を確認し、保存された画像辞書がどのように ScrapingResult(media={"images": [...]}) に渡されるかを調べます。次に MediaItem スキーマを確認し、どのフィールドが保持されるかを確認します。Issue の Pillow PDF の例で再現します。保存された各画像について、result.media.images から image_save_dir 配下のファイルを特定できる方法があり、インライン画像の動作も維持されていれば完了です。

索引モデルが issue の本文から書いたものです。

説明

🐞 Bug 🩺 Needs Triage
crawl4ai version

0.9.5 (develop at 78405d6)

Expected Behavior

With PDFContentScrapingStrategy(extract_images=True, save_images_locally=True), each entry in result.media.images should point at the image file that was written to image_save_dir.

Current Behavior

The image is written to disk, but the MediaItem in result.media.images has src == "" and data == "", so there is no way to find the file from the result.

The PDF processor reports a saved image as {"path": ..., "format": ..., "width": ..., ...}. scrap() passes these dicts straight into ScrapingResult(media={"images": [...]}), and MediaItem has no path field, so pydantic drops it. Same kind of schema mismatch as #2374 for links. Inline images (save_images_locally=False) are fine because data is a MediaItem field.

Is this reproducible?

Yes

Inputs Causing the Bug
Any PDF with an embedded image, e.g. one made by Pillow (below).
Steps to Reproduce
1. Make a one-page PDF containing an image.
2. Scrape it with PDFContentScrapingStrategy(extract_images=True, save_images_locally=True, image_save_dir=...).
3. Look at result.media.images.
Code snippets
import os, tempfile
from PIL import Image
from crawl4ai.processors.pdf import PDFContentScrapingStrategy

d = tempfile.mkdtemp()
pdf = os.path.join(d, "doc.pdf")
Image.new("RGB", (40, 30), "red").save(pdf)

strategy = PDFContentScrapingStrategy(
    extract_images=True, save_images_locally=True, image_save_dir=os.path.join(d, "imgs")
)
result = strategy.scrap(pdf, "")
print(os.listdir(os.path.join(d, "imgs")))
print(result.media.images[0].model_dump())

Output:

['page_1_img_1.jpg']
{'src': '', 'data': '', 'alt': '', 'desc': '', 'score': 0, 'type': 'image', 'group_id': 0, 'format': 'jpeg', 'width': 40}
OS

Linux

Python version

3.12

Browser

N/A (PDF scraping strategy called directly)

Browser version

N/A

Error logs & Screenshots (if applicable)

No error; success is True.

主要言語
Python
スター
86.8k
フォーク
9k
平均マージ
2日 12時間
マージ済み PR(30日)
21

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

unclecode/crawl4ai のほかの issue

unclecode/crawl4ai の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。