FillFormat — Aspose.Slides FOSS for Python API Reference

FillFormat controls how a shape’s interior (or a text portion’s color) is filled. It is accessed via shape.fill_format or portion.portion_format.fill_format.

Package: aspose.slides_foss

The fill type is selected by setting fill_format.fill_type to one of the FillType enumeration values. Only the sub-object matching the active fill_type is used; other sub-objects are ignored.


FillType Enumeration

ValueDescription
FillType.SOLIDUniform color fill. Configure via solid_fill_color.
FillType.GRADIENTSmooth color transition. Configure via gradient_format.
FillType.PATTERNRepeating geometric pattern. Configure via pattern_format.
FillType.PICTUREImage fill. Configure via picture_fill_format.
FillType.NO_FILLTransparent: no fill is applied.

FillFormat Properties

PropertyTypeDescription
fill_typeFillTypeActive fill type. Set this before configuring sub-objects.
solid_fill_colorColorFormatColor used when fill_type == FillType.SOLID.
gradient_formatGradientFormatGradient settings when fill_type == FillType.GRADIENT.
pattern_formatPatternFormatPattern settings when fill_type == FillType.PATTERN.
picture_fill_formatPictureFillFormatImage settings when fill_type == FillType.PICTURE.

ColorFormat

A ColorFormat wraps an ARGB color value.

PropertyTypeDescription
colorColorThe ARGB color. Assign a Color instance.

Color construction:

from aspose.slides_foss.drawing import Color

# From ARGB components (alpha, red, green, blue: each 0–255)
c = Color.from_argb(255, 30, 120, 200)   # opaque blue

# Named preset colors
Color.red        # ARGB(255, 255, 0, 0)
Color.blue       # ARGB(255, 0, 0, 255)
Color.dark_blue
Color.light_yellow
Color.gold
Color.white
Color.black

GradientFormat

PropertyTypeDescription
gradient_shapeGradientShapeShape of the gradient: LINEAR, RECTANGLE, RADIAL, PATH.
linear_gradient_anglefloatAngle in degrees for linear gradients (0 = left-to-right, 90 = top-to-bottom).
gradient_stopsGradientStopCollectionOrdered list of color stops. Each stop has a position (0.0–1.0) and a color.

GradientStopCollection Methods:

MethodDescription
add(position, color)Append a stop at position (float 0.0–1.0) with the given Color.

PatternFormat

PropertyTypeDescription
pattern_stylePatternStyleThe geometric tile pattern (50+ styles, e.g., PERCENT50, DARK_DOWNWARD_DIAGONAL).
fore_colorColorFormatForeground color (the pattern lines/dots).
back_colorColorFormatBackground color (the space between pattern lines).

PictureFillFormat

PropertyTypeDescription
picture_fill_modePictureFillModeHow the image fills the shape: STRETCH (scales to fill), TILE, TILE_FLIP.
picturePictureFillFormatPictureHolds the embedded image. Set picture.image to an Image from prs.images.add_image(bytes).

Usage Examples

Solid Fill

from aspose.slides_foss import ShapeType, FillType
from aspose.slides_foss.drawing import Color
import aspose.slides_foss as slides
from aspose.slides_foss.export import SaveFormat

with slides.Presentation() as prs:
    shape = prs.slides[0].shapes.add_auto_shape(ShapeType.RECTANGLE, 50, 50, 300, 150)
    shape.fill_format.fill_type = FillType.SOLID
    shape.fill_format.solid_fill_color.color = Color.from_argb(255, 0, 128, 255)
    prs.save("solid.pptx", SaveFormat.PPTX)

Linear Gradient (Blue → Red, 45°)

from aspose.slides_foss import ShapeType, FillType, GradientShape
from aspose.slides_foss.drawing import Color
import aspose.slides_foss as slides
from aspose.slides_foss.export import SaveFormat

with slides.Presentation() as prs:
    shape = prs.slides[0].shapes.add_auto_shape(ShapeType.RECTANGLE, 50, 50, 300, 150)
    shape.fill_format.fill_type = FillType.GRADIENT
    gf = shape.fill_format.gradient_format
    gf.gradient_shape = GradientShape.LINEAR
    gf.linear_gradient_angle = 45
    gf.gradient_stops.add(0.0, Color.blue)
    gf.gradient_stops.add(1.0, Color.red)
    prs.save("gradient.pptx", SaveFormat.PPTX)

Pattern Fill (50% Dark Blue on Light Yellow)

from aspose.slides_foss import ShapeType, FillType, PatternStyle
from aspose.slides_foss.drawing import Color
import aspose.slides_foss as slides
from aspose.slides_foss.export import SaveFormat

with slides.Presentation() as prs:
    shape = prs.slides[0].shapes.add_auto_shape(ShapeType.RECTANGLE, 50, 50, 300, 150)
    shape.fill_format.fill_type = FillType.PATTERN
    pf = shape.fill_format.pattern_format
    pf.pattern_style = PatternStyle.PERCENT50
    pf.fore_color.color = Color.dark_blue
    pf.back_color.color = Color.light_yellow
    prs.save("pattern.pptx", SaveFormat.PPTX)

Picture Fill (Stretched Image)

from aspose.slides_foss import ShapeType, FillType, PictureFillMode
import aspose.slides_foss as slides
from aspose.slides_foss.export import SaveFormat

with slides.Presentation() as prs:
    # Load image bytes from a file
    with open("background.png", "rb") as f:
        img_bytes = f.read()
    img = prs.images.add_image(img_bytes)

    shape = prs.slides[0].shapes.add_auto_shape(ShapeType.RECTANGLE, 0, 0, 720, 540)
    shape.fill_format.fill_type = FillType.PICTURE
    shape.fill_format.picture_fill_format.picture_fill_mode = PictureFillMode.STRETCH
    shape.fill_format.picture_fill_format.picture.image = img
    prs.save("picture-fill.pptx", SaveFormat.PPTX)

No Fill (Transparent Shape)

from aspose.slides_foss import ShapeType, FillType
import aspose.slides_foss as slides
from aspose.slides_foss.export import SaveFormat

with slides.Presentation() as prs:
    shape = prs.slides[0].shapes.add_auto_shape(ShapeType.RECTANGLE, 50, 50, 300, 150)
    shape.fill_format.fill_type = FillType.NO_FILL
    shape.add_text_frame("Transparent background")
    prs.save("no-fill.pptx", SaveFormat.PPTX)

See Also