Contents

textImageGenerator()

Generates a text image.

Declaration

class func textImageGenerator() -> any CIFilter & CITextImageGenerator

Return Value

The generated image.

Discussion

This method generates a 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 text image generator filter uses the following properties:

text

The string to render. The string can contain non-ASCII characters.

fontName

A string representing the name of the font to be used to generate the image.

fontSize

A float representing the size of the font as an NSNumber.

scaleFactor

A float representing the scale of the font for the generated text as an NSNumber.

The following code creates a filter that generates a string of text as a grayscale image:

func textImage(inputText: String) -> CIImage {
    let textImageGenerator = CIFilter.textImageGenerator()
    textImageGenerator.text = inputText
    textImageGenerator.fontName = "Helvetica"
    textImageGenerator.fontSize = 25
    textImageGenerator.scaleFactor = 4
    return textImageGenerator.outputImage!
}

[Image]

See Also

Filters