use image::{GenericImage, GenericImageView, ImageBuffer, Pixel, Primitive};
fn main() {
h_concat(&[
image::open("examples/concat/200x300.png").unwrap(),
image::open("examples/concat/300x300.png").unwrap(),
image::open("examples/concat/400x300.png").unwrap(),
])
.save("examples/concat/concatenated_900x300.png")
.unwrap();
}
fn h_concat<I, P, S>(images: &[I]) -> ImageBuffer<P, Vec<S>>
where
I: GenericImageView<Pixel = P>,
P: Pixel<Subpixel = S> + 'static,
S: Primitive + 'static,
{
let img_width_out: u32 = images.iter().map(|im| im.width()).sum();
let img_height_out: u32 = images.iter().map(|im| im.height()).max().unwrap_or(0);
let mut imgbuf = image::ImageBuffer::new(img_width_out, img_height_out);
let mut accumulated_width = 0;
for img in images {
imgbuf.copy_from(img, accumulated_width, 0).unwrap();
accumulated_width += img.width();
}
imgbuf
}