[Koha-bugs] [Bug 33674] New: Landscape cover images are resized ignoring if image/book cover width > height

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Thu May 4 10:44:08 CEST 2023


https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33674

            Bug ID: 33674
           Summary: Landscape cover images are resized ignoring  if
                    image/book cover width > height
 Change sponsored?: ---
           Product: Koha
           Version: 21.11
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P5 - low
         Component: Cataloging
          Assignee: koha-bugs at lists.koha-community.org
          Reporter: steve at softwaremage.co.nz
        QA Contact: testopia at bugs.koha-community.org
                CC: m.de.rooy at rijksmuseum.nl

The code fragments below (/Koha/CoverImage.pm) need to determine if the width
is greater than the height before resizing and creating the thumbnails and
'fullsize' image version. Otherwise  wide books are always resized as if they
were tall books. As a result the thumbnails and fullsize images of wide books
are always scaled smaller than their 'portrait' counterparts. 
Needless to say these hardcoded values should be part of system preferences.
They were set before the days of 4K monitors. I think that might be an open
item.

sub new {
    my ( $class, $params ) = @_;

    my $src_image = delete $params->{src_image};

    if ( $src_image ) {
          ; # GD autodetects three basic image formats: PNG, JPEG, XPM; we will
convert all to PNG which is lossless...

        # Check the pixel size of the image we are about to import...
        my $thumbnail = $class->_scale_image( $src_image, 140, 200 )
          ;    # MAX pixel dims are 140 X 200 for thumbnail...
        my $fullsize = $class->_scale_image( $src_image, 600, 800 )
          ;    # MAX pixel dims are 600 X 800 for full-size image...

        $params->{mimetype} = 'image/png';
        $params->{imagefile} = $fullsize->png();
        $params->{thumbnail} = $thumbnail->png();
    }

    return $class->SUPER::new($params);
}

sub _scale_image {
    my ( $self, $image, $maxwidth, $maxheight ) = @_;
    my ( $width, $height ) = $image->getBounds();
    if ( $width > $maxwidth || $height > $maxheight ) {

        my $percent_reduce;  # Percent we will reduce the image dimensions
by...
        if ( $width > $maxwidth ) {
            $percent_reduce =
              sprintf( "%.5f", ( $maxwidth / $width ) )
              ;    # If the width is oversize, scale based on width overage...
        }
        else {
            $percent_reduce =
              sprintf( "%.5f", ( $maxheight / $height ) )
              ;    # otherwise scale based on height overage.
        }
        my $width_reduce  = sprintf( "%.0f", ( $width * $percent_reduce ) );
        my $height_reduce = sprintf( "%.0f", ( $height * $percent_reduce ) );
        my $newimage = GD::Image->new( $width_reduce, $height_reduce, 1 )
          ;        #'1' creates true color image...
        $newimage->copyResampled( $image, 0, 0, 0, 0, $width_reduce,
            $height_reduce, $width, $height );
        return $newimage;
    }
    else {
        return $image;
    }
}

-- 
You are receiving this mail because:
You are the assignee for the bug.
You are watching all bug changes.


More information about the Koha-bugs mailing list