Bug 26172: (QA follow-up) Add missing filter
[koha.git] / opac / opac-image.pl
blob73426912b9f3e8ee17cc8d4540a6fcfbf2a94df1
1 #!/usr/bin/perl
3 # Copyright (C) 2011 C & P Bibliography Services
4 # Jared Camins-Esakov <jcamins@cpbibliograpy.com>
6 # based on patronimage.pl
8 # This file is part of Koha.
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.
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.
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>.
26 use Modern::Perl;
28 use CGI qw ( -utf8 );
29 use C4::Context;
30 use Koha::Biblios;
31 use Koha::CoverImages;
33 $| = 1;
35 my $DEBUG = 0;
36 my $data = CGI->new;
37 my $imagenumber;
39 =head1 NAME
41 opac-image.pl - Script for retrieving and formatting local cover images for display
43 =head1 SYNOPSIS
45 <img src="opac-image.pl?imagenumber=X" />
46 <img src="opac-image.pl?biblionumber=X" />
47 <img src="opac-image.pl?imagenumber=X&thumbnail=1" />
48 <img src="opac-image.pl?biblionumber=X&thumbnail=1" />
50 =head1 DESCRIPTION
52 This script, when called from within HTML and passed a valid imagenumber or
53 biblionumber, will retrieve the image data associated with that biblionumber
54 if one exists, format it in proper HTML format and pass it back to be displayed.
55 If the parameter thumbnail has been provided, a thumbnail will be returned
56 rather than the full-size image. When a biblionumber is provided rather than an
57 imagenumber, a random image is selected.
59 =cut
61 my ( $image );
62 if ( C4::Context->preference("OPACLocalCoverImages") ) {
63 my $imagenumber = $data->param('imagenumber');
64 my $biblionumber = $data->param('biblionumber');
65 if ( defined $imagenumber ) {
66 $imagenumber = $data->param('imagenumber');
67 $image = Koha::CoverImages->find($imagenumber);
69 elsif ( defined $biblionumber ) {
70 my $biblio = Koha::Biblios->find($biblionumber);
71 Koha::Exceptions::ObjectNotFound->throw( 'No bibliographic record for biblionumber ' . $biblionumber ) unless $biblio;
72 my $cover_images = $biblio->cover_images;
73 if ( $cover_images->count ) {
74 $image = $cover_images->next;
75 } else {
76 warn "No images for this biblio" if $DEBUG;
81 $image ||= Koha::CoverImages->no_image;
83 my $image_data =
84 $data->param('thumbnail')
85 ? $image->thumbnail
86 : $image->imagefile;
88 print $data->header(
89 -type => $image->mimetype,
90 -expires => '+30m',
91 -Content_Length => length($image_data)
92 ), $image_data;
94 =head1 AUTHOR
96 Chris Nighswonger cnighswonger <at> foundations <dot> edu
98 modified for local cover images by Koustubha Kale kmkale <at> anantcorp <dot> com
100 =cut