Bug 35520 - Add a script to export images from the db
Summary: Add a script to export images from the db
Status: NEW
Alias: None
Product: Koha
Classification: Unclassified
Component: Command-line Utilities (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Bugs List
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-12-08 10:23 UTC by Magnus Enger
Modified: 2023-12-08 11:16 UTC (History)
1 user (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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";

}