Gallery: Automatically adjust orientation of images based on EXIF data (RFE11498)

This commit is contained in:
kimd 2010-04-27 22:49:48 +02:00 committed by Doug Bell
parent 67f584d985
commit 660d036f8a
8 changed files with 229 additions and 3 deletions

View file

@ -19,11 +19,11 @@ use WebGUI::PseudoRequest;
use File::Spec;
use File::Temp qw/tempdir/;
use Image::Magick;
use Test::More;
use Test::Deep;
use Test::MockObject;
use Cwd;
use Data::Dumper;
use Path::Class::Dir;
my $session = WebGUI::Test->session;
@ -32,7 +32,7 @@ my $cwd = Cwd::cwd();
my ($extensionTests, $fileIconTests) = setupDataDrivenTests($session);
my $numTests = 136; # increment this value for each test you create
my $numTests = 140; # increment this value for each test you create
plan tests => $numTests + scalar @{ $extensionTests } + scalar @{ $fileIconTests };
my $uploadDir = $session->config->get('uploadsPath');
@ -539,6 +539,39 @@ is ($privs, '{"assets":[],"groups":["3","3"],"users":["3"]}', '... correct group
is ($privs, '{"assets":["' . $asset->getId . '"],"groups":[],"users":[]}', '... correct asset contents');
}
####################################################
#
# rotate
#
####################################################
# Create new storage for test of 'rotate' method
my $rotateTestStorage = WebGUI::Storage->create($session);
addToCleanup($rotateTestStorage);
# Add test image from file system
my $file = "rotation_test.png";
$rotateTestStorage->addFileFromFilesystem( WebGUI::Test->getTestCollateralPath($file) );
# Rotate image by 90° CW
$rotateTestStorage->rotate( $file, 90 );
# Test based on dimensions
cmp_deeply( [ $rotateTestStorage->getSizeInPixels($file) ], [ 3, 2 ], "rotate: check if image was rotated by 90° CW (based on dimensions)" );
# Test based on single pixel
my $image = new Image::Magick;
$image->Read( $rotateTestStorage->getPath( $file ) );
is( $image->GetPixel( x=>3, y=>1 ), 1, "rotate: check if image was rotated by 90° CW (based on pixels)");
# Rotate image by 90° CCW
$rotateTestStorage->rotate( $file, -90 );
# Test based on dimensions
cmp_deeply( [ $rotateTestStorage->getSizeInPixels($file) ], [ 2, 3 ], "rotate: check if image was rotated by 90° CCW (based on dimensions)" );
# Test based on single pixel
my $image = new Image::Magick;
$image->Read( $rotateTestStorage->getPath( $file ) );
is( $image->GetPixel( x=>1, y=>1 ), 1, "rotate: check if image was rotated by 90° CCW (based on pixels)");
####################################################
#