Skip to content

Latest commit

 

History

History
32 lines (21 loc) · 1.14 KB

simple_gradient.md

File metadata and controls

32 lines (21 loc) · 1.14 KB

Simple Gradient

The library provides convenient functions for creating horizontal and vertical gradients. We can call horizontal_gradient and vertical_gradient to create the gradients respectively.

use image::{imageops, Rgba};

fn main() {
    let mut img = image::open("my_image.jpg").unwrap();

    imageops::horizontal_gradient(
        &mut img,
        &Rgba::from([255, 255, 0, 255]),
        &Rgba::from([0, 0, 255, 255]),
    );

    img.save("horizontal_gradient.jpg").unwrap();
}

horizontal_gradient.jpg:

horizontal_gradient

To specify the two colors of the gradient, we pass two Rgbas, each describes a color that consists of red, green, blue and opaqueness.

vertical_gradient can be drawn similarly.

➡️ Next: Manipulating Pixels

📘 Back: Table of contents