#!/usr/bin/perl
use strict;
use warnings;
use Image::Imlib2;
my @files=("blue.png", "red.png");
my @mix=(255,192,128,64,0);
my ($image,$width,$height);
for (my $i=0;$i<=4;$i++){
blend($files[0],$mix[$i]);
my $clone=$image->clone;
blend($files[1],255-$mix[$i]);
$clone->blend($image,1 , 0, 0, $width, $height, 0, 0, $width, $height);
$clone->save("cloned-$i.png");
}
sub blend{
my($file,$new_alpha)=@_;
$image=Image::Imlib2->load($file);
$image->will_blend(0);#need this to be 0
$image->has_alpha(1);
$width = $image->width;
$height = $image->height;
for my $y (0 .. $height - 1) {
for my $x (0 .. $width - 1) {
my ($red, $green, $blue, $alpha) = $image->query_pixel($x, $y);
unless ($alpha==0){
$image->set_colour($red, $green, $blue, $new_alpha);
$image->draw_point($x, $y);
}
}
}
$image->will_blend(1);
return;
}