Bug 23140: Fix typo in branchcode parameters for print slip
[koha.git] / catalogue / image.pl
1 #!/usr/bin/perl
2 #
3 # Copyright (C) 2011 C & P Bibliography Services
4 # Jared Camins-Esakov <jcamins@cpbibliograpy.com>
5 #
6 # based on patronimage.pl
7 #
8 # This file is part of Koha.
9 #
10 # Koha is free software; you can redistribute it and/or modify it
11 # under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 3 of the License, or
13 # (at your option) any later version.
14 #
15 # Koha is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 #
23 #
24 #
25
26 use Modern::Perl;
27
28 use CGI qw ( -utf8 );    #qw(:standard escapeHTML);
29 use C4::Context;
30 use C4::Images;
31
32 $| = 1;
33
34 my $DEBUG = 0;
35 my $data  = new CGI;
36 my $imagenumber;
37
38 =head1 NAME
39
40 image.pl - Script for retrieving and formatting local cover images for display
41
42 =head1 SYNOPSIS
43
44 <img src="image.pl?imagenumber=X" />
45 <img src="image.pl?biblionumber=X" />
46 <img src="image.pl?imagenumber=X&thumbnail=1" />
47 <img src="image.pl?biblionumber=X&thumbnail=1" />
48
49 =head1 DESCRIPTION
50
51 This script, when called from within HTML and passed a valid imagenumber or
52 biblionumber, will retrieve the image data associated with that biblionumber
53 if one exists, format it in proper HTML format and pass it back to be displayed.
54 If the parameter thumbnail has been provided, a thumbnail will be returned
55 rather than the full-size image. When a biblionumber is provided rather than an
56 imagenumber, a random image is selected.
57
58 =cut
59
60 my ( $image, $mimetype ) = C4::Images->NoImage;
61 if ( C4::Context->preference("LocalCoverImages") ) {
62     if ( defined $data->param('imagenumber') ) {
63         $imagenumber = $data->param('imagenumber');
64     }
65     elsif ( defined $data->param('biblionumber') ) {
66         my @imagenumbers = ListImagesForBiblio( $data->multi_param('biblionumber') );
67         if (@imagenumbers) {
68             $imagenumber = $imagenumbers[0];
69         }
70         else {
71             warn "No images for this biblio" if $DEBUG;
72         }
73     }
74     else {
75         $imagenumber = shift;
76     }
77
78     if ($imagenumber) {
79         warn "imagenumber passed in: $imagenumber" if $DEBUG;
80         my $imagedata = RetrieveImage($imagenumber);
81         if ($imagedata) {
82             if ( $data->param('thumbnail') ) {
83                 $image = $imagedata->{'thumbnail'};
84             }
85             else {
86                 $image = $imagedata->{'imagefile'};
87             }
88             $mimetype = $imagedata->{'mimetype'};
89         }
90     }
91 }
92 print $data->header(
93     -type            => $mimetype,
94     -expires         => '+30m',
95     -Content_Length  => length($image)
96 ), $image;
97
98 =head1 AUTHOR
99
100 Chris Nighswonger cnighswonger <at> foundations <dot> edu
101
102 modified for local cover images by Koustubha Kale kmkale <at> anantcorp <dot> com
103
104 =cut