Composite with blend

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
tomredsky
Posts: 2
Joined: 2018-12-19T09:59:06-07:00
Authentication code: 1152

Composite with blend

Post by tomredsky » 2018-12-19T11:11:51-07:00

Hi,

I had been using PerlMagick to compose one image over another using v6.7.2-7 2017-03-22 Q16.
I updated to v7.0.8-17 Q16 and the syntax seems to have changed and I can not longer get the same results.

This sample code below give me an image that looks like this https://imgur.com/KngWDnS. There is no blend or opacity in the overlaid image and something is wrong with the dimensions. This script tries to write out a GIF, the requirement is for a jpeg.

Code: Select all

                                                                                                                                                                              
use v5.22;                                                                                            
use warnings;                                                                                         
use Image::Magick;                                                                                    
                                                                                                 
my $backgrd = 'dragon_sm.gif';                                                                        
my $image = Image::Magick->new(Verbose => 1);
print STDERR  $image->Get('version')."\n";                                       
my $x = $image->Read($backgrd);
warn $x if $x;

my $overlay = 'star.gif';                                                                             
my $wm = Image::Magick->new(Verbose => 1);                                                               
$x = $wm->Read($overlay);
warn $x if $x;

my %blend = (                                                                                         
    image      => $wm,                                                                                   
    compose => 'blend',                                                                               
    #blend     => "20",         # V6.7                                                                        
    blend       => '20,80',     # v7.0                                                                          
    gravity     => 'Center',
);
$image->Set(alpha => 'Set');                                                                                                                                       
$x = $image->Composite( %blend );                                                                     
warn $x if $x; 
    
my $out = '/tmp/compose-test_' . $blend{blend} .'.gif';                                                                                                      
$x = $image->Write(filename => $out);                                                                 
warn $x if $x;
This command-line version works and gives the desired output https://imgur.com/oItgCeq.

Code: Select all

convert dragon_sm.gif star.gif -compose blend -gravity center -define compose:args=20,80 -composite /tmp/dragon-star-file.jpg
I *thought* the syntax was `blend => "20,80"` but that doesn't work.

Does anyone know what the correct syntax or give any pointers on turning command-line syntax to perl?
Thanks
Dermot

tomredsky
Posts: 2
Joined: 2018-12-19T09:59:06-07:00
Authentication code: 1152

Re: Composite with blend

Post by tomredsky » 2018-12-29T10:08:38-07:00

I've found that setting the 'clip-to-self' attribute to true with Composite corrects the problem of the image dimensions. Still digging around for a workable blend solution. I've found that setting

Code: Select all

opacity => '20%'
to work but I'm not sure if it's exactly what I used to get from setting

Code: Select all

blend => 20

Post Reply