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