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=doc)
# There are several ways of setting image.
shape = builder.insert_shape(shape_type=aw.drawing.ShapeType.RECTANGLE, width=80, height=80)
# 1 -  Using a local system filename:
shape.fill.set_image(file_name=IMAGE_DIR + 'Logo.jpg')
doc.save(file_name=ARTIFACTS_DIR + 'Shape.FillImage.FileName.docx')
# 2 -  Load a file into a byte array:
shape.fill.set_image(image_bytes=system_helper.io.File.read_all_bytes(IMAGE_DIR + 'Logo.jpg'))
doc.save(file_name=ARTIFACTS_DIR + 'Shape.FillImage.ByteArray.docx')
# 3 -  From a stream:
with system_helper.io.FileStream(IMAGE_DIR + 'Logo.jpg', system_helper.io.FileMode.OPEN) as stream:
    shape.fill.set_image(stream=stream)
doc.save(file_name=ARTIFACTS_DIR + 'Shape.FillImage.Stream.docx')

See Also