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