Image — Aspose.Note FOSS for Python API Reference

Class: Image

Package: aspose.note Import: from aspose.note import Image Inherits: CompositeNode

Image represents an embedded image stored inside a OneNote .one file. It exposes the raw image bytes, the original filename, rendered dimensions, alt text, a hyperlink URL (if any), and any OneNote tags attached to the image.


Properties

PropertyTypeAccessDescription
FileNamestr | NoneReadOriginal filename as stored in the OneNote file; None if not present
BytesbytesReadRaw image data (PNG, JPEG, or other binary format depending on source)
Widthfloat | NoneReadRendered width in points
Heightfloat | NoneReadRendered height in points
AlternativeTextTitlestr | NoneReadAccessibility alt text title: always None for files parsed in v26.2; the parser does not populate this field
AlternativeTextDescriptionstr | NoneReadAccessibility alt text description
HyperlinkUrlstr | NoneReadURL if the image is a clickable link
Tagslist[NoteTag]ReadOneNote tags attached to this image

Inherited from CompositeNode / Node

PropertyDescription
ParentNodeContaining node (OutlineElement, TableCell)
DocumentRoot Document

Methods

Replace(image)

img.Replace(image: Image) -> None

Replaces the content of this Image node with the content of another Image node, in-memory. Saving back to .one is not supported.


Accept(visitor)

img.Accept(visitor: DocumentVisitor) -> None

Dispatches VisitImageStart(img) and VisitImageEnd(img) on the visitor.


Usage Examples

Save all images to disk

from aspose.note import Document, Image

doc = Document("MyNotes.one")
for i, img in enumerate(doc.GetChildNodes(Image), start=1):
    filename = img.FileName or f"image_{i}.bin"
    with open(filename, "wb") as f:
        f.write(img.Bytes)
    print(f"Saved: {filename}  ({img.Width} x {img.Height} pts)")

Detect image format from bytes

from aspose.note import Document, Image

doc = Document("MyNotes.one")
for img in doc.GetChildNodes(Image):
    b = img.Bytes
    if b[:4] == b'\x89PNG':
        fmt = "png"
    elif b[:2] == b'\xff\xd8':
        fmt = "jpeg"
    elif b[:4] == b'GIF8':
        fmt = "gif"
    else:
        fmt = "bin"
    print(f"  {img.FileName!r} detected as {fmt}")

Find all linked images

from aspose.note import Document, Image

doc = Document("MyNotes.one")
for img in doc.GetChildNodes(Image):
    if img.HyperlinkUrl:
        print(f"  Linked image: {img.FileName!r} -> {img.HyperlinkUrl}")

Read alt text

from aspose.note import Document, Image

doc = Document("MyNotes.one")
for img in doc.GetChildNodes(Image):
    if img.AlternativeTextTitle or img.AlternativeTextDescription:
        print(f"  Alt title: {img.AlternativeTextTitle!r}")
        print(f"  Alt desc:  {img.AlternativeTextDescription!r}")

Inspect tags on images

from aspose.note import Document, Image

doc = Document("MyNotes.one")
for img in doc.GetChildNodes(Image):
    for tag in img.Tags:
        print(f"  Image tag: label={tag.label!r}  completed={tag.completed}")

Images per page

from aspose.note import Document, Page, Image

doc = Document("MyNotes.one")
for page_num, page in enumerate(doc.GetChildNodes(Page), start=1):
    images = page.GetChildNodes(Image)
    print(f"Page {page_num}: {len(images)} image(s)")

None-Safety

  • FileName is None when no filename was stored: always provide a fallback when writing to disk.
  • Bytes is always a bytes object and is never None.
  • Width and Height are None for images with no dimension metadata.
  • AlternativeTextTitle, AlternativeTextDescription, and HyperlinkUrl are None when not set.

See Also