set_image method

set_image(file_name)

Changes the fill type to single image.

def set_image(self, file_name: str):
    ...
ParameterTypeDescription
file_namestrThe path to the image file.

set_image(stream)

Changes the fill type to single image.

def set_image(self, stream: io.BytesIO):
    ...
ParameterTypeDescription
streamio.BytesIOThe stream that contains the image bytes.

set_image(image_bytes)

Changes the fill type to single image.

def set_image(self, image_bytes: bytes):
    ...
ParameterTypeDescription
image_bytesbytesThe image bytes array.

Examples

Shows how to set shape fill type as image.

doc = aw.Document()
builder = aw.DocumentBuilder(doc)
# There are several ways of setting image.
shape = builder.insert_shape(aw.drawing.ShapeType.RECTANGLE, 80, 80)
# 1 -  Using a local system filename:
shape.fill.set_image(IMAGE_DIR + 'Logo.jpg')
doc.save(ARTIFACTS_DIR + 'Shape.fill_image.file_name.docx')
# 2 -  Load a file into a byte array:
with open(IMAGE_DIR + 'Logo.jpg', 'rb') as stream:
    shape.fill.set_image(stream.read())
doc.save(ARTIFACTS_DIR + 'Shape.fill_image.byte_array.docx')
# 3 -  From a stream:
with open(IMAGE_DIR + 'Logo.jpg', 'rb') as stream:
    shape.fill.set_image(stream)
doc.save(ARTIFACTS_DIR + 'Shape.fill_image.stream.docx')

See Also