[][src]Function raster::editor::blend

pub fn blend(
    image1: &Image,
    image2: &Image,
    blend_mode: BlendMode,
    opacity: f32,
    position: PositionMode,
    offset_x: i32,
    offset_y: i32
) -> RasterResult<Image>

Blend 2 images into one. The image1 is the base and image2 is the top.

Opacity is any value from 0.0 - 1.0

The offset_x and offset_y are added to the final position. Can also be negative offsets.

Errors

If image2 falls outside the canvas area, then this fails with RasterError::BlendingImageFallsOutsideCanvas.

Examples

use raster::{editor, BlendMode, PositionMode};

// Create images from file
let image1 = raster::open("tests/in/sample.jpg").unwrap();
let image2 = raster::open("tests/in/watermark.png").unwrap();

// Blend image2 on top of image1 using normal mode, opacity of 1.0 (100%), with image2 at the
// center, with 0 x and 0 y offsets. whew
let normal = editor::blend(&image1, &image2, BlendMode::Normal, 1.0, PositionMode::Center, 0, 0).unwrap();

// All the other blend modes
let difference = editor::blend(&image1, &image2, BlendMode::Difference, 1.0, PositionMode::Center, 0, 0).unwrap();
let multiply = editor::blend(&image1, &image2, BlendMode::Multiply, 1.0, PositionMode::Center, 0, 0).unwrap();
let overlay = editor::blend(&image1, &image2, BlendMode::Overlay, 1.0, PositionMode::Center, 0, 0).unwrap();
let screen = editor::blend(&image1, &image2, BlendMode::Screen, 1.0, PositionMode::Center, 0, 0).unwrap();

// Save it
raster::save(&normal, "tests/out/test_blend_normal.png").unwrap();
raster::save(&difference, "tests/out/test_blend_difference.png").unwrap();
raster::save(&multiply, "tests/out/test_blend_multiply.png").unwrap();
raster::save(&overlay, "tests/out/test_blend_overlay.png").unwrap();
raster::save(&screen, "tests/out/test_blend_screen.png").unwrap();

Source Images

Image 1

Image 2

Blended Images

Normal

Difference

Multiply

Overlay

Screen