- start of external Imager API access:
[imager.git] / t / t66paste.t
CommitLineData
92bda632
TC
1#!perl -w
2use strict;
3use Test::More tests => 15;
02d1d628 4
92bda632 5BEGIN { use_ok("Imager") }
02d1d628
AMH
6
7#$Imager::DEBUG=1;
8
9Imager::init('log'=>'testout/t66paste.log');
10
92bda632
TC
11# the original smoke tests
12my $img=Imager->new() || die "unable to create image object\n";
02d1d628 13
92bda632 14ok($img->open(file=>'testimg/scale.ppm',type=>'pnm'), "load test img");
02d1d628 15
92bda632
TC
16my $nimg=Imager->new() or die "Unable to create image object\n";
17ok($nimg->open(file=>'testimg/scale.ppm',type=>'pnm'), "load test img again");
02d1d628 18
92bda632
TC
19ok($img->paste(img=>$nimg, top=>30, left=>30), "paste it")
20 or print "# ", $img->errstr, "\n";;
02d1d628 21
92bda632
TC
22ok($img->write(type=>'pnm',file=>'testout/t66.ppm'), "save it")
23 or print "# ", $img->errstr, "\n";
02d1d628 24
92bda632
TC
25# more stringent tests
26{
27 my $src = Imager->new(xsize => 100, ysize => 100);
28 $src->box(filled=>1, color=>'FF0000');
02d1d628 29
92bda632
TC
30 $src->box(filled=>1, color=>'0000FF', xmin => 20, ymin=>20,
31 xmax=>79, ymax=>79);
02d1d628 32
92bda632
TC
33 my $targ = Imager->new(xsize => 100, ysize => 100);
34 $targ->box(filled=>1, color=>'00FF00', xmin=>20, ymin=>20, xmax=>79,
35 ymax=>79);
02d1d628 36
92bda632
TC
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,
43 color=>'0000FF');
44
45 is(Imager::i_img_diff($work->{IMG}, $cmp->{IMG}), 0,
46 "compare pasted and expected");
47
48 $work = $targ->copy;
49 ok($work->paste(src=>$src, left=>2, top=>7, src_minx => 10, src_miny => 15),
50 "paste from inside src");
51 $cmp = $targ->copy;
52 $cmp->box(filled=>1, xmin=>2, ymin=>7, xmax=>91, ymax=>91, color=>'FF0000');
53 $cmp->box(filled=>1, xmin=>12, ymin=>12, xmax=>71, ymax=>71,
54 color=>'0000FF');
55 is(Imager::i_img_diff($work->{IMG}, $cmp->{IMG}), 0,
56 "compare pasted and expected");
57
58 # paste part source
59 $work = $targ->copy;
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");
63 $cmp = $targ->copy;
64 $cmp->box(filled=>1, xmin=>15, ymin=>20, xmax=>84, ymax=>74,
65 color=>'FF0000');
66 $cmp->box(filled=>1, xmin=>25, ymin=>25, xmax=>84, ymax=>74,
67 color=>'0000FF');
68 is(Imager::i_img_diff($work->{IMG}, $cmp->{IMG}), 0,
69 "compare pasted and expected");
70
71 # go by width instead
72 $work = $targ->copy;
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");
78
79 # use src_coords
80 $work = $targ->copy;
81 ok($work->paste(src=>$src, left => 15, top => 20,
82 src_coords => [ 10, 15, 80, 70 ]),
83 "using src_coords");
84 is(Imager::i_img_diff($work->{IMG}, $cmp->{IMG}), 0,
85 "compare pasted and expected");
86}