4 use Test::More tests => 15;
6 BEGIN { use_ok("Imager") }
10 Imager::init('log'=>'testout/t66paste.log');
12 # the original smoke tests
13 my $img=Imager->new() || die "unable to create image object\n";
15 ok($img->open(file=>'testimg/scale.ppm',type=>'pnm'), "load test img");
17 my $nimg=Imager->new() or die "Unable to create image object\n";
18 ok($nimg->open(file=>'testimg/scale.ppm',type=>'pnm'), "load test img again");
20 ok($img->paste(img=>$nimg, top=>30, left=>30), "paste it")
21 or print "# ", $img->errstr, "\n";;
23 ok($img->write(type=>'pnm',file=>'testout/t66.ppm'), "save it")
24 or print "# ", $img->errstr, "\n";
26 # more stringent tests
28 my $src = Imager->new(xsize => 100, ysize => 100);
29 $src->box(filled=>1, color=>'FF0000');
31 $src->box(filled=>1, color=>'0000FF', xmin => 20, ymin=>20,
34 my $targ = Imager->new(xsize => 100, ysize => 100);
35 $targ->box(filled=>1, color=>'00FF00', xmin=>20, ymin=>20, xmax=>79,
38 my $work = $targ->copy;
39 ok($work->paste(src=>$src, left => 15, top => 10), "paste whole image");
40 # build comparison image
41 my $cmp = $targ->copy;
42 $cmp->box(filled=>1, xmin=>15, ymin => 10, color=>'FF0000');
43 $cmp->box(filled=>1, xmin=>35, ymin => 30, xmax=>94, ymax=>89,
46 is(Imager::i_img_diff($work->{IMG}, $cmp->{IMG}), 0,
47 "compare pasted and expected");
50 ok($work->paste(src=>$src, left=>2, top=>7, src_minx => 10, src_miny => 15),
51 "paste from inside src");
53 $cmp->box(filled=>1, xmin=>2, ymin=>7, xmax=>91, ymax=>91, color=>'FF0000');
54 $cmp->box(filled=>1, xmin=>12, ymin=>12, xmax=>71, ymax=>71,
56 is(Imager::i_img_diff($work->{IMG}, $cmp->{IMG}), 0,
57 "compare pasted and expected");
61 ok($work->paste(src=>$src, left=>15, top=>20,
62 src_minx=>10, src_miny=>15, src_maxx=>80, src_maxy =>70),
63 "paste src cropped all sides");
65 $cmp->box(filled=>1, xmin=>15, ymin=>20, xmax=>84, ymax=>74,
67 $cmp->box(filled=>1, xmin=>25, ymin=>25, xmax=>84, ymax=>74,
69 is(Imager::i_img_diff($work->{IMG}, $cmp->{IMG}), 0,
70 "compare pasted and expected");
74 ok($work->paste(src=>$src, left=>15, top=>20,
75 src_minx=>10, src_miny => 15, width => 70, height => 55),
76 "same but specify width/height instead");
77 is(Imager::i_img_diff($work->{IMG}, $cmp->{IMG}), 0,
78 "compare pasted and expected");
82 ok($work->paste(src=>$src, left => 15, top => 20,
83 src_coords => [ 10, 15, 80, 70 ]),
85 is(Imager::i_img_diff($work->{IMG}, $cmp->{IMG}), 0,
86 "compare pasted and expected");