Skip to content
Pixer
Esc
navigateopen⌘Jpreview
On this page

Image operations

Resize, crop, rotate, flip, and adjust images.

Direct operations return a new Pixer instance and leave the original image unchanged.

Resize

final fitted = image.resize(800, 600);
final exact = image.resizeExact(800, 600);

resize preserves the aspect ratio. resizeExact may stretch or squash the image.

Choose a resize filter when needed:

final pixels = image.resize(
  320,
  240,
  filter: FilterTypeEnum.Nearest,
);

The available filters are Nearest, Triangle, CatmullRom, Gaussian, and Lanczos3. Lanczos3 is the default.

Crop

final cropped = image.crop(100, 100, 400, 300);

The arguments are x, y, width, and height. The crop rectangle must fit inside the image.

Rotate and flip

final clockwise = image.rotate90();
final upsideDown = image.rotate180();
final counterClockwise = image.rotate270();
final mirrored = image.flipHorizontal();
final vertical = image.flipVertical();

Adjust

final soft = image.blur(2.5);
final lighter = image.brightness(30);
final punchier = image.contrast(20);
final gray = image.grayscale();
final negative = image.invert();

Remember to dispose every returned image after use. For several operations, prefer a batch so intermediate images remain inside Rust.

Was this page helpful?