[SOLVED] CopyPixels() isn't copying. [Missing something BA-SIC]

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
E. Fudd Wabbitwy
Posts: 27
Joined: 2019-09-18T08:46:14-07:00
Authentication code: 1152

[SOLVED] CopyPixels() isn't copying. [Missing something BA-SIC]

Post by E. Fudd Wabbitwy »

In this example, I am trying to copy the top half/bottom half of two different images into a third, but in fact neither of the CopyPixels() registers (the 4th Write is identical to the 3rd). I'm sure I'm missing something basic because even SetPixel() doesn't work. (Like a "commit" step?)

Can you say what might be missing? Thank you.

Code: Select all

#!/usr/bin/perl
use strict;
use Image::Magick;

my $imageblue = Image::Magick->new;
$imageblue->Set('size'=>'50x50');
$imageblue->ReadImage('xc:blue');
$imageblue->Write('win:'); #or 'show:'
$imageblue->Write('SourceBLUE.png');

my $imagered = Image::Magick->new;
$imagered->Set('size'=>'50x50');
$imagered->ReadImage('xc:red');
$imagered->Write('win:'); #or 'show:'
$imagered->Write('SourceRED.png');

my $imagewhite = Image::Magick->new;
$imagewhite->Set('size'=>'50x50');
$imagewhite->ReadImage('xc:white');
$imagewhite->Write('win:'); #or 'show:'
$imagewhite->Write('TargetWHITE.png');

# read red top paste white top
$imagewhite->CopyPixels($imagered,geometry=>'50x25+0+0',dx=>0,dy=>0); # SYNTAX: missing 'image=>' before $imagered
# read blue top paste white bottom
$imagewhite->CopyPixels($imageblue,geometry=>'50x25+0+0',dx=>0,dy=>25); # Ditto

$imagewhite->Write('win:'); #or 'show:'
$imagewhite->Write('TargetREDBLUE.png');
Last edited by E. Fudd Wabbitwy on 2019-09-23T19:28:16-07:00, edited 1 time in total.
E. Fudd Wabbitwy
Posts: 27
Joined: 2019-09-18T08:46:14-07:00
Authentication code: 1152

Re: CopyPixels() isn't copying. [Missing something BA-SIC]

Post by E. Fudd Wabbitwy »

The BA-SIC missing piece, found by more trial-and-error, was the parameter name '$image=>' before the image name:

Code: Select all

$imagewhite->CopyPixels([b]image=>[/b]$imagered,geometry=>'50x25+0+0',dx=>0,dy=>0);
Post Reply