From 046c7f59534fddf76475a11babb24f30b1151f6e Mon Sep 17 00:00:00 2001 From: Hinemoea Viault Date: Mon, 29 May 2023 12:18:34 -0400 Subject: [PATCH] Bug 33857: Add script to resize cover images --- misc/maintenance/resize_cover_images.pl | 74 +++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100755 misc/maintenance/resize_cover_images.pl diff --git a/misc/maintenance/resize_cover_images.pl b/misc/maintenance/resize_cover_images.pl new file mode 100755 index 0000000000..6f9df99d7b --- /dev/null +++ b/misc/maintenance/resize_cover_images.pl @@ -0,0 +1,74 @@ + +#!/usr/bin/perl + +# This file is part of Koha. +# +# Copyright 2019 Koha Development Team +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + + +use Modern::Perl; + +use CGI qw ( -utf8 ); + +use Koha::CoverImages; +use Image::Magick; #sudo apt install imagemagick +$| = 1; + +my @images = Koha::CoverImages->as_list(); +my $image; +my $i =0; +print "Vous avez " . scalar @images . " images. \n"; + +my $dbh = C4::Context->dbh; +my $sth = $dbh->prepare("SELECT round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB` FROM information_schema.TABLES WHERE table_schema = '$ENV{'KOHADB'}' AND table_name = 'cover_images';"); +$sth->execute(); +my @test = $sth->fetchrow_array(); +print "La taile de tout les images dans $ENV{'KOHADB'} est de ". $test[0]. "MG avant.\n"; + print "[..........] 0-1000 images \r ["; +for ( @images ) { + $i++; + #print $i ."\n"; + my $im = Image::Magick->new; + $image = ""; + + $im->BlobToImage($_->imagefile); + $im->Resize( geometry => '300x400' ); + + $image = $im->ImageToBlob(); + + + $_->update( + {imagefile => $image} + ); + + if($i % 100 == 0) + { + print "*"; + if($i % 1000 == 0){ + print "]\r[..........] $i-".($i+1000)." images \r ["; + } + } +} +print "\n". $i . " images traité.\n"; +my $query = "optimize table cover_images"; + + my $sthOp = $dbh->prepare($query); + +$sthOp->execute; + +$sth->execute(); +@test = $sth->fetchrow_array(); +print "La taile de tout les images dans $ENV{'KOHADB'} est de ". $test[0]. "MG apres.\n"; \ No newline at end of file -- 2.34.1