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