save method

save(stream)

Saves the image into the specified stream.

def save(self, stream: io.BytesIO):
    ...
ParameterTypeDescription
streamio.BytesIOThe stream where to save the image to.

Remarks

Is it the responsibility of the caller to dispose the stream object.

save(file_name)

Saves the image into a file.

def save(self, file_name: str):
    ...
ParameterTypeDescription
file_namestrThe file name where to save the image.

Examples

Shows how to save all images from a document to the file system.

img_source_doc = aw.Document(file_name=MY_DIR + 'Images.docx')
# Get all shape nodes and filter those that have images
shapes_with_images = []
for node in img_source_doc.get_child_nodes(aw.NodeType.SHAPE, True):
    shape = node.as_shape()
    if shape.has_image:
        shapes_with_images.append(shape)
# Go through each shape and save its image.
shape_index = 0
while shape_index < len(shapes_with_images):
    image_data = shapes_with_images[shape_index].image_data
    image_data.save(ARTIFACTS_DIR + f'Drawing.SaveAllImages.{shape_index + 1}.{image_data.image_type}')
    shape_index += 1

See Also