From 8d1e47a6ce8ed11cc7aa0c4cd14cda820c730b79 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Wed, 19 Dec 2007 18:04:50 +0000 Subject: [PATCH] Storage/Image: resize works with ImageMagick again. Add diagnostics to tests for easy debug --- lib/WebGUI/Storage/Image.pm | 14 +++++++------- t/Storage/Image.t | 10 ++++++++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/WebGUI/Storage/Image.pm b/lib/WebGUI/Storage/Image.pm index 008c75fae..70f3cce77 100644 --- a/lib/WebGUI/Storage/Image.pm +++ b/lib/WebGUI/Storage/Image.pm @@ -382,14 +382,14 @@ sub resize { $self->session->errorHandler->error("Couldn't read image for resizing: ".$error); return 0; } - my $geometry; - if (!$width || !$height) { - $geometry = $width || $height; - } - else { - $geometry = $width . "x" . $height; + my ($x, $y) = $image->Get('width','height'); + if (!$height) { # proportional scale by width + $height = $width / $x * $y; } - $image->Resize( geometry => $geometry, filter => "lanczos" ); + elsif (!$width) { # proportional scale by height + $width = $height * $x / $y; + } + $image->Resize( height => $height, width => $width, filter => "lanczos" ); $error = $image->Write($self->getPath($filename)); if ($error) { $self->session->errorHandler->error("Couldn't resize image: ".$error); diff --git a/t/Storage/Image.t b/t/Storage/Image.t index e2f4dcd9b..390d3357d 100644 --- a/t/Storage/Image.t +++ b/t/Storage/Image.t @@ -259,16 +259,22 @@ foreach my $testImage (@testImages) { ); } +use Data::Dumper; + $session->setting->set('maxImageSize', $resizeTarget ); foreach my $testImage (@testImages) { my $filename = $testImage->{ filename }; + #diag $filename; + #diag "orig size: ". Dumper([ $sizeTest->getSizeInPixels($filename) ]); is($sizeTest->adjustMaxImageSize($filename), 1, "$filename needs to be resized"); my @newSize = $sizeTest->getSizeInPixels($filename); - diag sprintf("%s -> new size = %d x %d", $filename, @newSize); + #diag sprintf("%s -> new size = %d x %d", $filename, @newSize); + #diag $WebGUI::Test::logger_warns; + #diag $WebGUI::Test::logger_error; cmp_bag( [ $sizeTest->getSizeInPixels($filename) ], [ @{ $testImage }{qw/newHeight newWidth/} ], - "$testImage was resized properly" + "$filename was resized properly" ); }