View | Details | Raw Unified | Return to bug 33857
Collapse All | Expand All

(-)a/misc/maintenance/resize_cover_images.pl (-1 / +74 lines)
Line 0 Link Here
0
- 
1
2
#!/usr/bin/perl
3
4
# This file is part of Koha.
5
#
6
# Copyright 2019 Koha Development Team
7
#
8
# Koha is free software; you can redistribute it and/or modify it
9
# under the terms of the GNU General Public License as published by
10
# the Free Software Foundation; either version 3 of the License, or
11
# (at your option) any later version.
12
#
13
# Koha is distributed in the hope that it will be useful, but
14
# WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
17
#
18
# You should have received a copy of the GNU General Public License
19
# along with Koha; if not, see <http://www.gnu.org/licenses>.
20
21
22
use Modern::Perl;
23
24
use CGI qw ( -utf8 );
25
26
use Koha::CoverImages;
27
use Image::Magick; #sudo apt install imagemagick
28
$| = 1;
29
30
my @images = Koha::CoverImages->as_list();
31
my $image;
32
my $i =0;
33
print "Vous avez " . scalar @images . " images. \n";
34
35
my $dbh  = C4::Context->dbh;
36
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';");
37
$sth->execute();
38
my @test = $sth->fetchrow_array();
39
print "La taile de tout les images dans $ENV{'KOHADB'} est de ". $test[0]. "MG avant.\n";
40
    print "[..........] 0-1000 images \r [";
41
for ( @images ) {
42
    $i++;
43
    #print $i ."\n";
44
    my $im = Image::Magick->new;
45
    $image = "";
46
47
    $im->BlobToImage($_->imagefile);
48
    $im->Resize( geometry => '300x400' );
49
50
    $image = $im->ImageToBlob();
51
52
53
    $_->update(
54
        {imagefile => $image}
55
    );
56
57
    if($i % 100 == 0)
58
    {
59
        print  "*";
60
        if($i % 1000 == 0){
61
            print "]\r[..........] $i-".($i+1000)." images \r [";
62
        }
63
    }
64
}
65
print "\n". $i . " images traité.\n";
66
my $query = "optimize table cover_images";
67
68
 my $sthOp = $dbh->prepare($query);
69
70
$sthOp->execute;
71
72
$sth->execute();
73
@test = $sth->fetchrow_array();
74
print "La taile de tout les images dans $ENV{'KOHADB'} est de ". $test[0]. "MG apres.\n";

Return to bug 33857