| 1 | #!/usr/bin/perl -w |
|---|
| 2 | # $Id$ |
|---|
| 3 | |
|---|
| 4 | use strict; |
|---|
| 5 | use warnings; |
|---|
| 6 | |
|---|
| 7 | use lib 't/lib'; |
|---|
| 8 | use lib 'lib'; |
|---|
| 9 | use lib 'extlib'; |
|---|
| 10 | |
|---|
| 11 | use MT::Test; |
|---|
| 12 | use Test::More; |
|---|
| 13 | use File::Spec; |
|---|
| 14 | |
|---|
| 15 | use MT::Image; |
|---|
| 16 | use MT::ConfigMgr; |
|---|
| 17 | use MT; |
|---|
| 18 | |
|---|
| 19 | use vars qw( @Img @drivers ); |
|---|
| 20 | |
|---|
| 21 | BEGIN { |
|---|
| 22 | @Img = ( |
|---|
| 23 | [ 'test.gif', 233, 68 ], |
|---|
| 24 | [ 'test.jpg', 640, 480 ], |
|---|
| 25 | ); |
|---|
| 26 | @drivers = qw( ImageMagick NetPBM GD ); |
|---|
| 27 | plan tests => scalar @Img # file exists |
|---|
| 28 | + (scalar @Img * scalar @drivers * 19) # 19 tests each for every image and driver |
|---|
| 29 | ; |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | MT->set_language('en-us'); |
|---|
| 33 | |
|---|
| 34 | my $File = "test.file"; |
|---|
| 35 | my $String = "testing"; |
|---|
| 36 | my $netpbm = '/usr/local/netpbm/bin'; |
|---|
| 37 | |
|---|
| 38 | my $cfg = MT::ConfigMgr->instance; |
|---|
| 39 | if (!$cfg->NetPBMPath) { |
|---|
| 40 | $cfg->NetPBMPath($netpbm) if -x $netpbm; |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | for my $rec (@Img) { |
|---|
| 44 | my ($img_filename, $img_width, $img_height) = @$rec; |
|---|
| 45 | my $img_file = File::Spec->catfile($ENV{MT_HOME}, 't', 'images', $img_filename); |
|---|
| 46 | ok(-B $img_file, "$img_file looks like a binary file"); |
|---|
| 47 | |
|---|
| 48 | for my $driver (@drivers) { |
|---|
| 49 | $cfg->ImageDriver($driver); |
|---|
| 50 | my $img = MT::Image->new( Filename => $img_file ); |
|---|
| 51 | SKIP : { |
|---|
| 52 | # skip("no $driver image", 19) unless $img; |
|---|
| 53 | isa_ok($img, 'MT::Image::' . $driver, "driver $driver with image $img_file is an MT::Image::$driver"); |
|---|
| 54 | # diag( MT::Image->errstr ) if MT::Image->errstr; |
|---|
| 55 | |
|---|
| 56 | is($img->{width}, $img_width, "$driver says $img_filename is $img_width px wide"); |
|---|
| 57 | is($img->{height}, $img_height, "$driver says $img_filename is $img_height px high"); |
|---|
| 58 | my($w, $h) = $img->get_dimensions(); |
|---|
| 59 | is($w, $img_width, "${driver}'s get_dimensions says $img_filename is $img_width px wide"); |
|---|
| 60 | is($h, $img_height, "${driver}'s get_dimensions says $img_filename is $img_height px high"); |
|---|
| 61 | |
|---|
| 62 | ($w, $h) = $img->get_dimensions(Scale => 50); |
|---|
| 63 | my($x, $y) = (int($img_width / 2), int($img_height / 2)); |
|---|
| 64 | is($w, $x, "$driver says $img_filename at 50\% scale is $x px wide"); |
|---|
| 65 | is($h, $y, "$driver says $img_filename at 50\% scale is $y px high"); |
|---|
| 66 | |
|---|
| 67 | ($w, $h) = $img->get_dimensions(); |
|---|
| 68 | is($w, $img_width, "${driver}'s get_dimensions says $img_filename is still $img_width px wide after theoretical scaling"); |
|---|
| 69 | is($h, $img_height, "${driver}'s get_dimensions says $img_filename is still $img_height px high after theoretical scaling"); |
|---|
| 70 | |
|---|
| 71 | ($w, $h) = $img->get_dimensions(Width => 50); |
|---|
| 72 | is($w, 50, "$driver says $img_filename scaled to 50 px wide is 50 px wide"); |
|---|
| 73 | |
|---|
| 74 | ($w, $h) = $img->get_dimensions(Width => 50, Height => 100); |
|---|
| 75 | is($w, 50, "$driver says $img_filename scaled to 50x100 is 50 px wide"); |
|---|
| 76 | is($h, 100, "$driver says $img_filename scaled to 50x100 is 100 px high"); |
|---|
| 77 | |
|---|
| 78 | (my($blob), $w, $h) = $img->scale(Scale => 50); |
|---|
| 79 | ($x, $y) = (int($img_width / 2), int($img_height / 2)); |
|---|
| 80 | is($w, $x, "result of scaling $img_filename to 50\% with $driver is $x px wide"); |
|---|
| 81 | is($h, $y, "result of scaling $img_filename to 50\% with $driver is $y px high"); |
|---|
| 82 | |
|---|
| 83 | open FH, $img_file or die $!; |
|---|
| 84 | binmode FH; |
|---|
| 85 | my $data = do { local $/; <FH> }; |
|---|
| 86 | close FH; |
|---|
| 87 | (my $type = $img_file) =~ s/.*\.//; |
|---|
| 88 | $img = MT::Image->new( Data => $data, Type => $type ); |
|---|
| 89 | isa_ok($img, 'MT::Image::' . $driver); |
|---|
| 90 | # diag( MT::Image->errstr ) if MT::Image->errstr; |
|---|
| 91 | is($img->{width}, $img_width, "$driver says $img_filename from blob is $img_width px wide"); |
|---|
| 92 | is($img->{height}, $img_height, "$driver says $img_filename from blob is $img_height px high"); |
|---|
| 93 | ($w, $h) = $img->get_dimensions; |
|---|
| 94 | is($w, $img_width, "${driver}'s get_dimensions says $img_filename from blob is $img_width px wide"); |
|---|
| 95 | is($h, $img_height, "${driver}'s get_dimensions says $img_filename from blob is $img_height px high"); |
|---|
| 96 | } # END SKIP |
|---|
| 97 | } |
|---|
| 98 | } |
|---|