Transformations
Hokusai provides typed image operations that can be freely composed into a single pipeline.
Resize and crop
Section titled “Resize and crop”let cover = try image.resize( width: 1200, height: 630, fit: .cover, position: .attention)
let region = try image.extract(x: 100, y: 80, width: 640, height: 480)Resize supports fit (inside, outside, fill, cover, contain), crop position, kernel, background, and enlargement/reduction controls. Use autoOrient() near the start of a recipe to respect EXIF orientation.
Geometry and appearance
Section titled “Geometry and appearance”let prepared = try image .autoOrient() .rotate(by: 90) .blur(sigma: 2.5) .sharpen() .flatten(background: .white)Geometry operations include resize, extract, extend, rotate, flip, flop, affine, trim and smartCrop. Appearance operations include blur, sharpen, grayscale, tint, normalize, clahe, gamma, modulate and more; see Geometry, Effects & color and Channels & transparency.
Encode the result
Section titled “Encode the result”let webp = try await prepared.webp(quality: 82).data()let avif = try await prepared.avif(quality: 50).data()Choose the output encoder late in the recipe. See Formats & Compatibility for supported output formats.