Bug 35520

Summary: Add a script to export images from the db
Product: Koha Reporter: Magnus Enger <magnus>
Component: Command-line UtilitiesAssignee: Bugs List <koha-bugs>
Status: NEW --- QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: robin
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:

Description Magnus Enger 2023-12-08 10:23:43 UTC
Could be useful both for cover_images and patronimage.
Comment 1 Magnus Enger 2023-12-08 10:44:04 UTC
Or is there a standard way to do this that makes a special script unnecessary? I imagine we want to put things like biblionumber and borrowernumber in the filename, which might make a generic solution har to use.
Comment 2 Magnus Enger 2023-12-08 11:16:10 UTC
Here's a very basic POC, just for cover images. Feel free to build on it if you can beat me to it! :-) 

use Koha::CoverImages;
use File::Slurper qw( write_binary );
use Modern::Perl;

my $outputdir = '.';

my $covers = Koha::CoverImages->search();
while ( my $cover = $covers->next ) {

    my $biblionumber = $cover->biblionumber;
    my $imagenumber = $cover->imagenumber;
    my $itemnumber = $cover->itemnumber; # Can be NULL

    my $filename = "$outputdir/biblionumber_$biblionumber" . "_imagenumber_$imagenumber" . "_full.png";
    write_binary( $filename, $cover->imagefile );
    say "Wrote $filename";

    my $thumbnail = "$outputdir/biblionumber_$biblionumber" . "_imagenumber_$imagenumber" . "_thumb.png";
    write_binary( $thumbnail, $cover->thumbnail );
    say "Wrote $thumbnail";

}