Contents

attributedTextImageGenerator()

Generates an attributed-text image.

Declaration

class func attributedTextImageGenerator() -> any CIFilter & CIAttributedTextImageGenerator

Return Value

The generated image.

Discussion

This method generates an attributed-text image. The effect takes the input string property and the scale factor to scale up the text. You commonly combine this filter with other filters to create a watermark on images.

The attributed-text image generator filter uses the following properties:

text

An NSAttributedString.

scaleFactor

A float representing the scale of the font to use for the generated text.

padding

A float representing the value for an additional number of pixels to pad around the text’s bounding box.

The following code creates a filter that generates an attributed-text image:

func attributedTextImage() -> CIImage {
    let attributedTextImageFilter = CIFilter.attributedTextImageGenerator()
    attributedTextImageFilter.text = NSAttributedString(string: "Hello world! 👋")
    attributedTextImageFilter.scaleFactor = 10
    attributedTextImageFilter.padding = 5
    return attributedTextImageFilter.outputImage!
}

[Image]

See Also

Filters