3 use Test::More tests => 23;
5 BEGIN { use_ok("Imager") }
9 Imager::init('log'=>'testout/t66paste.log');
11 # the original smoke tests
12 my $img=Imager->new() || die "unable to create image object\n";
14 ok($img->open(file=>'testimg/scale.ppm',type=>'pnm'), "load test img");
16 my $nimg=Imager->new() or die "Unable to create image object\n";
17 ok($nimg->open(file=>'testimg/scale.ppm',type=>'pnm'), "load test img again");
19 ok($img->paste(img=>$nimg, top=>30, left=>30), "paste it")
20 or print "# ", $img->errstr, "\n";;
22 ok($img->write(type=>'pnm',file=>'testout/t66.ppm'), "save it")
23 or print "# ", $img->errstr, "\n";
25 # more stringent tests
27 my $src = Imager->new(xsize => 100, ysize => 110);
28 $src->box(filled=>1, color=>'FF0000');
30 $src->box(filled=>1, color=>'0000FF', xmin => 20, ymin=>20,
33 my $targ = Imager->new(xsize => 100, ysize => 110);
34 $targ->box(filled=>1, color =>'00FFFF');
35 $targ->box(filled=>1, color=>'00FF00', xmin=>20, ymin=>20, xmax=>79,
37 my $work = $targ->copy;
38 ok($work->paste(src=>$src, left => 15, top => 10), "paste whole image");
39 # build comparison image
40 my $cmp = $targ->copy;
41 $cmp->box(filled=>1, xmin=>15, ymin => 10, color=>'FF0000');
42 $cmp->box(filled=>1, xmin=>35, ymin => 30, xmax=>94, ymax=>89,
45 is(Imager::i_img_diff($work->{IMG}, $cmp->{IMG}), 0,
46 "compare pasted and expected");
49 ok($work->paste(src=>$src, left=>2, top=>7, src_minx => 10, src_miny => 15),
50 "paste from inside src");
52 $cmp->box(filled=>1, xmin=>2, ymin=>7, xmax=>91, ymax=>101, color=>'FF0000');
53 $cmp->box(filled=>1, xmin=>12, ymin=>12, xmax=>71, ymax=>71,
55 is(Imager::i_img_diff($work->{IMG}, $cmp->{IMG}), 0,
56 "compare pasted and expected");
60 ok($work->paste(src=>$src, left=>15, top=>20,
61 src_minx=>10, src_miny=>15, src_maxx=>80, src_maxy =>70),
62 "paste src cropped all sides");
64 $cmp->box(filled=>1, xmin=>15, ymin=>20, xmax=>84, ymax=>74,
66 $cmp->box(filled=>1, xmin=>25, ymin=>25, xmax=>84, ymax=>74,
68 is(Imager::i_img_diff($work->{IMG}, $cmp->{IMG}), 0,
69 "compare pasted and expected");
73 ok($work->paste(src=>$src, left=>15, top=>20,
74 src_minx=>10, src_miny => 15, width => 70, height => 55),
75 "same but specify width/height instead");
76 is(Imager::i_img_diff($work->{IMG}, $cmp->{IMG}), 0,
77 "compare pasted and expected");
81 ok($work->paste(src=>$src, left => 15, top => 20,
82 src_coords => [ 10, 15, 80, 70 ]),
84 is(Imager::i_img_diff($work->{IMG}, $cmp->{IMG}), 0,
85 "compare pasted and expected");
89 # supplying just src_maxx would set the internal maxy to undef
90 # supplying just src_maxy would be ignored
91 # src_maxy (or it's derived value) was being bounds checked against
92 # the image width instead of the image height
95 local $SIG{__WARN__} = sub { push @warns, "@_"; print "# @_"; };
97 ok($work->paste(src=>$src, left => 15, top => 20,
99 "paste with just src_maxx");
100 ok(!@warns, "shouldn't warn");
101 my $cmp = $targ->copy;
102 $cmp->box(filled=>1, color => 'FF0000', xmin => 15, ymin => 20,
103 xmax => 64, ymax => 109);
104 $cmp->box(filled=>1, color => '0000FF', xmin => 35, ymin => 40,
105 xmax => 64, ymax => 99);
106 is(Imager::i_img_diff($work->{IMG}, $cmp->{IMG}), 0,
107 "check correctly pasted");
111 ok($work->paste(src=>$src, left=>15, top=>20,
113 "paste with just src_maxy");
114 ok(!@warns, "shouldn't warn");
116 $cmp->box(filled => 1, color => 'FF0000', xmin => 15, ymin => 20,
117 xmax => 99, ymax => 79);
118 $cmp->box(filled => 1, color => '0000FF', xmin => 35, ymin => 40,
119 xmax => 94, ymax => 79);
120 is(Imager::i_img_diff($work->{IMG}, $cmp->{IMG}), 0,
121 "check pasted correctly");
125 ok($work->paste(src=>$src, left=>15, top=>20,
126 src_miny => 20, src_maxy => 105),
127 "paste with src_maxy > source width");
130 $cmp->box(filled => 1, color => 'FF0000', xmin => 15, ymin => 20,
132 $cmp->box(filled => 1, color => '0000FF', xmin => 35, ymin => 20,
133 xmax => 94, ymax => 79);
134 is(Imager::i_img_diff($work->{IMG}, $cmp->{IMG}), 0,
135 "check pasted correctly");