Commits

Anonymous committed 3152481 Draft

Changed ratio handling so that size is a max cap for 'longest side', regardless if that is the width or the height (looked at Image::Thumbnail for inspiration)

  • Participants
  • Parent commits 51aa83e

Comments (0)

Files changed (1)

lib/GD/Thumbnail.pm

 }
 
 sub _check_ratio {
-   my($self, $max, $w) = @_;
+   my($self, $max, $w, $h) = @_;
    my $ratio;
    if ( $max =~ RE_RATIO ) {
       $ratio = $1;
    }
    else {
-      $ratio = sprintf '%.1f', $max * RATIO_CONSTANT / $w;
+#	$ratio = sprintf '%.1f', $max * RATIO_CONSTANT / $w;
+	$ratio = ($w/$max) > ($h/$max) ? ($w/$max) : ($h/$max);
    }
    croak 'Can not determine thumbnail ratio' if ! $ratio;
    return $ratio;
    my $size      = $info2 ? $self->_image_size( $image ) : 0;
    my $gd        = GD::Image->new($image) or croak "GD::Image->new error: $!";
    my($w, $h)    = $gd->getBounds         or croak "getBounds() failed: $!";
-   my $ratio     = $self->_check_ratio($max, $w);
+   my $ratio     = $self->_check_ratio($max, $w, $h);
    my $square    = $self->{SQUARE} || 0;
    my $crop      = $square && lc $square eq 'crop';
 
-   my $x         = sprintf '%.0f', $w * $ratio / RATIO_CONSTANT;
-   my $def_y     = sprintf '%.0f', $h * $ratio / RATIO_CONSTANT;
+#   my $x         = sprintf '%.0f', $w * $ratio / RATIO_CONSTANT;
+#   my $def_y     = sprintf '%.0f', $h * $ratio / RATIO_CONSTANT;
+
+	my $x = int( $w/$ratio );
+	my $def_y = int( $h/$ratio );
+
    my $y         = $square ? $x : $def_y;
    my $yy        = 0; # yy & yy2 has the same value
    my $yy2       = 0;