#!/usr/bin/perl use warnings; use Image::Magick; use strict; #From the command line, this is the result I'd like to achieve: # composite -dissolve 87.8 foreground.jpg -size 500x500 xc:white output.jpg; # composite mask.png output.jpg output.jpg my $mask = Image::Magick->new(magick=>'png'); my $background = Image::Magick->new(magick=>'png'); my $foreground = Image::Magick->new(magick=>'png'); $mask->Read("png:zzzmask.png"); $background->Set(size=>'500x500'); $background->Read("xc:white"); $background->Set(magick=>'png'); $foreground->Read("zzzforeground.jpg"); $foreground->Set(magick=>'png'); $background->Composite(compose=>'Atop', image=>$foreground, opacity => '50.8%' ); $background->Composite(image=>$mask); $background->Write("zzzpoutput.png"); exit; # The mask can be any png with transparency (any kind of watermark), # and foreground any 500x500 image.