OneNote में Python का उपयोग करके इमेज मेटाडेटा कैसे पढ़ें

OneNote में Python का उपयोग करके इमेज मेटाडेटा कैसे पढ़ें

हर Image OneNote दस्तावेज़ में प्रत्येक नोड कच्चे पिक्सेल बाइट्स के साथ मेटाडेटा रखता है: मूल फ़ाइलनाम, प्रदर्शन आयाम (बिंदुओं में चौड़ाई और ऊँचाई), अभिगम्यता के लिए वैकल्पिक पाठ, और यदि छवि लिंक की गई थी तो वैकल्पिक रूप से एक हाइपरलिंक URL। Aspose.Note FOSS for Python इन सभी फ़ील्ड्स को … के माध्यम से उजागर करता है Image क्लास।.


पूर्वापेक्षाएँ

pip install aspose-note

इमेज गुण

गुणप्रकारविवरण
img.Bytesbytesकच्चा छवि डेटा। इसे डिस्क पर लिखें, साथ में open(name, "wb").write(img.Bytes).
img.FileName`strNone`
img.Width`floatNone`
img.Height`floatNone`
img.AlternativeTextDescription`strNone`
img.AlternativeTextTitle`strNone`
img.HyperlinkUrl`strNone`
img.Tagslist[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 मानकों के अनुरूप।.

संबंधित देखें

 हिन्दी