Lines 18-29
package C4::Images;
Link Here
|
18 |
# You should have received a copy of the GNU General Public License |
18 |
# You should have received a copy of the GNU General Public License |
19 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
19 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
20 |
|
20 |
|
21 |
use strict; |
21 |
use Modern::Perl; |
22 |
use warnings; |
|
|
23 |
use 5.010; |
24 |
|
22 |
|
25 |
use C4::Context; |
23 |
use C4::Context; |
26 |
use GD; |
24 |
use GD; |
|
|
25 |
use Koha::Exceptions; |
27 |
|
26 |
|
28 |
use vars qw($debug $noimage @ISA @EXPORT); |
27 |
use vars qw($debug $noimage @ISA @EXPORT); |
29 |
|
28 |
|
Lines 47-64
BEGIN {
Link Here
|
47 |
|
46 |
|
48 |
=head2 PutImage |
47 |
=head2 PutImage |
49 |
|
48 |
|
50 |
PutImage($biblionumber, $srcimage, $replace); |
49 |
PutImage({ biblionumber => $biblionumber, itemnumber => $itemnumber, src_image => $srcimage, replace => $replace }); |
51 |
|
50 |
|
52 |
Stores binary image data and thumbnail in database, optionally replacing existing images for the given biblio. |
51 |
Stores binary image data and thumbnail in database, optionally replacing existing images for the given biblio or item. |
53 |
|
52 |
|
54 |
=cut |
53 |
=cut |
55 |
|
54 |
|
56 |
sub PutImage { |
55 |
sub PutImage { |
57 |
my ( $biblionumber, $srcimage, $replace ) = @_; |
56 |
my ( $params ) = @_; |
|
|
57 |
|
58 |
my $biblionumber = $params->{biblionumber}; |
59 |
my $itemnumber = $params->{itemnumber}; |
60 |
my $srcimage = $params->{src_image}; |
61 |
my $replace = $params->{replace}; |
62 |
|
63 |
Koha::Exceptions::WrongParameter->throw( |
64 |
'PutImage cannot be called with both biblionumber and itemnumber') |
65 |
if $biblionumber and $itemnumber; |
66 |
|
67 |
Koha::Exceptions::WrongParameter->throw( |
68 |
'PutImage must be called with "replace" if itemnumber is passed. Only 1 cover per item is allowed.') |
69 |
if $itemnumber and not $replace; |
70 |
|
58 |
|
71 |
|
59 |
return -1 unless defined($srcimage); |
72 |
return -1 unless defined($srcimage); |
60 |
|
73 |
|
61 |
if ($replace) { |
74 |
if ($biblionumber && $replace) { |
62 |
foreach ( ListImagesForBiblio($biblionumber) ) { |
75 |
foreach ( ListImagesForBiblio($biblionumber) ) { |
63 |
DelImage($_); |
76 |
DelImage($_); |
64 |
} |
77 |
} |
Lines 66-72
sub PutImage {
Link Here
|
66 |
|
79 |
|
67 |
my $dbh = C4::Context->dbh; |
80 |
my $dbh = C4::Context->dbh; |
68 |
my $query = |
81 |
my $query = |
69 |
"INSERT INTO biblioimages (biblionumber, mimetype, imagefile, thumbnail) VALUES (?,?,?,?);"; |
82 |
"INSERT INTO biblioimages (biblionumber, itemnumber, mimetype, imagefile, thumbnail) VALUES (?,?,?,?,?);"; |
70 |
my $sth = $dbh->prepare($query); |
83 |
my $sth = $dbh->prepare($query); |
71 |
|
84 |
|
72 |
my $mimetype = 'image/png' |
85 |
my $mimetype = 'image/png' |
Lines 79-88
sub PutImage {
Link Here
|
79 |
; # MAX pixel dims are 600 X 800 for full-size image... |
92 |
; # MAX pixel dims are 600 X 800 for full-size image... |
80 |
$debug and warn "thumbnail is " . length($thumbnail) . " bytes."; |
93 |
$debug and warn "thumbnail is " . length($thumbnail) . " bytes."; |
81 |
|
94 |
|
82 |
$sth->execute( $biblionumber, $mimetype, $fullsize->png(), |
95 |
$sth->execute( $biblionumber, $itemnumber, $mimetype, $fullsize->png(), |
83 |
$thumbnail->png() ); |
96 |
$thumbnail->png() ); |
84 |
my $dberror = $sth->errstr; |
97 |
my $dberror = $sth->errstr; |
85 |
warn "Error returned inserting $biblionumber.$mimetype." if $sth->errstr; |
98 |
warn sprintf("Error returned inserting %s.%s.", ($biblionumber || $itemnumber, $mimetype)) if $sth->errstr; |
86 |
undef $thumbnail; |
99 |
undef $thumbnail; |
87 |
undef $fullsize; |
100 |
undef $fullsize; |
88 |
return $dberror; |
101 |
return $dberror; |
Lines 135-140
sub ListImagesForBiblio {
Link Here
|
135 |
return @imagenumbers; |
148 |
return @imagenumbers; |
136 |
} |
149 |
} |
137 |
|
150 |
|
|
|
151 |
=head2 GetImageForItem |
152 |
my $image = GetImageForItem($itemnumber); |
153 |
|
154 |
Gets the image associated with a particular item. |
155 |
|
156 |
=cut |
157 |
|
158 |
sub GetImageForItem { |
159 |
my ($itemnumber) = @_; |
160 |
|
161 |
my $dbh = C4::Context->dbh; |
162 |
return $dbh->selectrow_array( |
163 |
'SELECT imagenumber FROM biblioimages WHERE itemnumber = ?', |
164 |
undef, $itemnumber ); |
165 |
} |
166 |
|
138 |
=head2 DelImage |
167 |
=head2 DelImage |
139 |
|
168 |
|
140 |
my ($dberror) = DelImage($imagenumber); |
169 |
my ($dberror) = DelImage($imagenumber); |