From 3c90f4f80775cc634f08c9157538440e5bb26d72 Mon Sep 17 00:00:00 2001 From: Hammat Wele Date: Fri, 20 Dec 2024 18:26:56 +0000 Subject: [PATCH] Bug 8088: Png-images of covers lost transparency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Images of covers must preserve transparency of png-images. This is useful for example for the covers of CD/DVD disks. Plan test : 1. Apply the patch. 2. In 'Koha administration > System preferences', set 'LocalCoverImages' to 'show' and OPACLocalCoverImages to 'show'. 3. Create a new bibligraphical record 4. In the record details select tab Images and click on upload 5. click on « Drop files here » and select the image file to upload then click «Process images» 6. Search for the record created on step 3 7. Click on the record to view detail page (detail.pl) 8. Click on the image to view it fully --->Notice the background is transparent 9. Save the image and open it ---> Notice the background is transparent Signed-off-by: esther --- Koha/CoverImage.pm | 15 ++++++++++++++- tools/upload-cover-image.pl | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Koha/CoverImage.pm b/Koha/CoverImage.pm index e5467bedeb..0d9e1faf44 100644 --- a/Koha/CoverImage.pm +++ b/Koha/CoverImage.pm @@ -67,6 +67,11 @@ sub new { $params->{mimetype} = 'image/png'; $params->{imagefile} = $fullsize->png(); $params->{thumbnail} = $thumbnail->png(); + # Convert the image to PNG and print it on standard output + + open my $fh1, '>', '/inlibro/BD/outputV.png'; + print {$fh1} $params->{thumbnail}; + close $fh1; } return $class->SUPER::new($params); @@ -94,10 +99,18 @@ sub _scale_image { ; #'1' creates true color image... $newimage->copyResampled( $image, 0, 0, 0, 0, $width_reduce, $height_reduce, $width, $height ); + my $background = $newimage->colorAllocate(0,0,0); + $newimage->transparent($background); return $newimage; } else { - return $image; + my $newimage = GD::Image->new( $width, $height, 1 ); + ; #'1' creates true color image... + $newimage->copyResampled( $image, 0, 0, 0, 0, $width, + $height, $width, $height ); + my $background = $newimage->colorAllocate(0,0,0); + $newimage->transparent($background); + return $newimage; } } diff --git a/tools/upload-cover-image.pl b/tools/upload-cover-image.pl index e78f360947..8627e50286 100755 --- a/tools/upload-cover-image.pl +++ b/tools/upload-cover-image.pl @@ -102,6 +102,7 @@ if ( $op eq 'cud-process' && $fileID ) { my $upload = Koha::UploadedFiles->find( $fileID ); if ( $filetype eq 'image' ) { my $fh = $upload->file_handle; + GD::Image->trueColor(1); my $srcimage = GD::Image->new($fh); $fh->close if $fh; if ( defined $srcimage ) { -- 2.39.5