OneNote에서 Python으로 이미지 메타데이터 읽는 방법
모든 Image OneNote 문서의 노드는 원시 픽셀 바이트와 함께 메타데이터를 포함합니다: 원본 파일명, 표시 차원(포인트 단위의 너비와 높이), 접근성을 위한 대체 텍스트, 그리고 이미지가 링크된 경우 선택적으로 하이퍼링크 URL도 포함합니다. Aspose.Note FOSS for Python는 이러한 모든 필드를 통해 Image 클래스.
전제 조건
pip install aspose-note이미지 속성
| 속성 | 유형 | 설명 |
|---|---|---|
img.Bytes | bytes | 원시 이미지 데이터. 디스크에 쓰려면 open(name, "wb").write(img.Bytes). |
img.FileName | `str | None` |
img.Width | `float | None` |
img.Height | `float | None` |
img.AlternativeTextDescription | `str | None` |
img.AlternativeTextTitle | `str | None` |
img.HyperlinkUrl | `str | None` |
img.Tags | list[NoteTag] | 이 이미지에 첨부된 OneNote 태그(별표, 체크박스 등). |
단계 1: 문서를 로드하고 이미지 찾기
from aspose.note import Document, Image
doc = Document("MyNotes.one")
images = doc.GetChildNodes(Image)
print(f"Found {len(images)} image(s)")단계 2: 각 이미지의 메타데이터 읽기
모든 nullable 필드를 다음으로 보호하십시오 is not None 사용하기 전에:
from aspose.note import Document, Image
doc = Document("MyNotes.one")
for i, img in enumerate(doc.GetChildNodes(Image), start=1):
print(f"\nImage {i}:")
print(f" Filename: {img.FileName or '(no filename)'}")
print(f" Size: {img.Bytes and len(img.Bytes):,} bytes")
if img.Width is not None and img.Height is not None:
print(f" Dimensions: {img.Width:.1f} × {img.Height:.1f} pts")
if img.AlternativeTextDescription:
print(f" Alt text: {img.AlternativeTextDescription}")
if img.HyperlinkUrl:
print(f" Hyperlink: {img.HyperlinkUrl}")
if img.Tags:
for tag in img.Tags:
print(f" Tag: {tag.Label or tag.Icon}")전체 예제: 메타데이터 보고서와 함께 이미지 저장
from pathlib import Path
from aspose.note import Document, Image
def report_and_save_images(one_path: str, out_dir: str = "images") -> None:
doc = Document(one_path)
images = doc.GetChildNodes(Image)
if not images:
print("No images found.")
return
out = Path(out_dir)
out.mkdir(exist_ok=True)
for i, img in enumerate(images, start=1):
# Determine save name
name = img.FileName or f"image_{i}.bin"
dest = out / name
# Save bytes
dest.write_bytes(img.Bytes)
# Report metadata
dims = (
f"{img.Width:.0f}×{img.Height:.0f}pts"
if img.Width is not None and img.Height is not None
else "unknown size"
)
alt = img.AlternativeTextDescription or ""
link = img.HyperlinkUrl or ""
print(f" [{i}] {name} {dims}"
+ (f" alt='{alt}'" if alt else "")
+ (f" url={link}" if link else ""))
print(f"\nSaved {len(images)} image(s) to '{out_dir}/'")
report_and_save_images("MyNotes.one")속성별 이미지 필터링
하이퍼링크가 있는 이미지
from aspose.note import Document, Image
doc = Document("MyNotes.one")
linked = [img for img in doc.GetChildNodes(Image) if img.HyperlinkUrl]
for img in linked:
print(f"{img.FileName or 'image'} → {img.HyperlinkUrl}")대체 텍스트가 있는 이미지
from aspose.note import Document, Image
doc = Document("MyNotes.one")
with_alt = [img for img in doc.GetChildNodes(Image) if img.AlternativeTextDescription]
for img in with_alt:
print(f"{img.FileName}: {img.AlternativeTextDescription}")노트
img.Bytes항상 존재합니다 (반환b""읽을 수 없는 이미지에 대해, 절대None). 확인len(img.Bytes) > 0저장하기 전에.img.AlternativeTextTitle일 수 있습니다None원본 문서가 제목을 설정하지 않은 경우. 사용img.AlternativeTextDescription대체값으로.- 크기 단위는 포인트 (1 포인트 = 1/72 인치), PowerPoint 및 PDF 규격과 일치합니다.