Lines 23-28
use C4::Auth;
Link Here
|
23 |
use Graphics::Magick; |
23 |
use Graphics::Magick; |
24 |
use XML::Simple; |
24 |
use XML::Simple; |
25 |
use POSIX qw(ceil); |
25 |
use POSIX qw(ceil); |
|
|
26 |
use Storable qw(dclone); |
26 |
use autouse 'Data::Dumper' => qw(Dumper); |
27 |
use autouse 'Data::Dumper' => qw(Dumper); |
27 |
|
28 |
|
28 |
use C4::Debug; |
29 |
use C4::Debug; |
Lines 125-135
if ($layout_xml->{'page_side'} eq 'B') { # rearrange items on backside of page t
Link Here
|
125 |
@{$items} = @swap_array; |
126 |
@{$items} = @swap_array; |
126 |
} |
127 |
} |
127 |
|
128 |
|
|
|
129 |
# WARNING: Referential nightmare ahead... |
130 |
|
128 |
CARD_ITEMS: |
131 |
CARD_ITEMS: |
129 |
foreach my $item (@{$items}) { |
132 |
foreach my $item (@{$items}) { |
130 |
if ($item) { |
133 |
if ($item) { |
131 |
my $print_layout_xml = (( ($cardscount % 2 == 1) && ( $layout_back_id ) ) ? |
134 |
my $print_layout_xml = (( ($cardscount % 2 == 1) && ( $layout_back_id ) ) ? |
132 |
$layout_back_xml : $layout_xml ); |
135 |
dclone($layout_back_xml) : dclone($layout_xml) ); # We must have a true copy of the layout xml hash, otherwise |
|
|
136 |
# we modify the original template and very bad things happen. |
133 |
|
137 |
|
134 |
$cardscount ++; |
138 |
$cardscount ++; |
135 |
my $borrower_number = $item->{'borrower_number'}; |
139 |
my $borrower_number = $item->{'borrower_number'}; |
Lines 159-170
foreach my $item (@{$items}) {
Link Here
|
159 |
my $error = undef; |
163 |
my $error = undef; |
160 |
my $images = $print_layout_xml->{'images'}; |
164 |
my $images = $print_layout_xml->{'images'}; |
161 |
PROCESS_IMAGES: |
165 |
PROCESS_IMAGES: |
162 |
foreach (keys %{$images}) { |
166 |
foreach my $card_image (sort(keys %{$images})) { |
163 |
if (grep{m/source/} keys(%{$images->{$_}->{'data_source'}->[0]})) { |
167 |
if (grep{m/(source)/} keys(%{$images->{$card_image}->{'data_source'}->[0]})) { |
164 |
if ($images->{$_}->{'data_source'}->[0]->{'image_source'} eq 'none') { |
168 |
if ($images->{$card_image}->{'data_source'}->[0]->{'image_source'} eq 'none') { |
165 |
next PROCESS_IMAGES; |
|
|
166 |
} |
169 |
} |
167 |
elsif ($images->{$_}->{'data_source'}->[0]->{'image_source'} eq 'patronimages') { |
170 |
elsif ($images->{$card_image}->{'data_source'}->[0]->{'image_source'} eq 'patronimages') { |
168 |
my $patron_image = Koha::Patron::Images->find($borrower_number); |
171 |
my $patron_image = Koha::Patron::Images->find($borrower_number); |
169 |
if ($patron_image) { |
172 |
if ($patron_image) { |
170 |
$image_data->{'imagefile'} = $patron_image->imagefile; |
173 |
$image_data->{'imagefile'} = $patron_image->imagefile; |
Lines 172-198
foreach my $item (@{$items}) {
Link Here
|
172 |
else { |
175 |
else { |
173 |
warn sprintf('No image exists for borrower number %s.', $borrower_number); |
176 |
warn sprintf('No image exists for borrower number %s.', $borrower_number); |
174 |
} |
177 |
} |
175 |
next PROCESS_IMAGES unless $patron_image; |
|
|
176 |
} |
178 |
} |
177 |
elsif ($images->{$_}->{'data_source'}->[0]->{'image_source'} eq 'creator_images') { |
179 |
elsif ($images->{$card_image}->{'data_source'}->[0]->{'image_source'} eq 'creator_images') { |
|
|
180 |
## FIXME: The DB stuff here needs to be religated to a Koha::Creator::Images object -chris_n |
178 |
my $dbh = C4::Context->dbh(); |
181 |
my $dbh = C4::Context->dbh(); |
179 |
$dbh->{LongReadLen} = 1000000; # allows us to read approx 1MB |
182 |
$dbh->{LongReadLen} = 1000000; # allows us to read approx 1MB |
180 |
$image_data = $dbh->selectrow_hashref("SELECT imagefile FROM creator_images WHERE image_name = \'$images->{$_}->{'data_source'}->[0]->{'image_name'}\'"); |
183 |
$image_data = $dbh->selectrow_hashref("SELECT imagefile FROM creator_images WHERE image_name = \'$images->{$card_image}->{'data_source'}->[0]->{'image_name'}\'"); |
181 |
warn sprintf('Database returned the following error: %s.', $error) if $error; |
184 |
warn sprintf('Database returned the following error: %s.', $error) if $error; |
182 |
warn sprintf('Image does not exists in db table %s.', $images->{$_}->{'data_source'}->[0]->{'image_name'}) if !$image_data; |
185 |
unless($image_data){ |
183 |
next PROCESS_IMAGES if !$image_data; |
186 |
warn sprintf('Image does not exists in db table %s.', $images->{$card_image}->{'data_source'}->[0]->{'image_name'}); |
|
|
187 |
} |
184 |
} |
188 |
} |
185 |
else { |
189 |
else { |
186 |
warn sprintf('No retrieval method for image source %s.', $images->{$_}->{'data_source'}->[0]->{'image_source'}); |
190 |
warn sprintf('No retrieval method for image source %s.', $images->{$card_image}->{'data_source'}->[0]->{'image_source'}); |
187 |
next PROCESS_IMAGES; |
|
|
188 |
} |
191 |
} |
189 |
} |
192 |
} |
190 |
else { |
193 |
else { |
191 |
warn sprintf("Unrecognized image data source: %s", $images->{$_}->{'data_source'}); |
194 |
warn sprintf("Unrecognized image data source: %s", $images->{$card_image}->{'data_source'}); |
192 |
next PROCESS_IMAGES; |
|
|
193 |
} |
195 |
} |
194 |
|
196 |
|
195 |
my $binary_data = $image_data->{'imagefile'}; |
197 |
my $binary_data = $image_data->{'imagefile'} || next PROCESS_IMAGES; |
196 |
|
198 |
|
197 |
# invoke the display image object... |
199 |
# invoke the display image object... |
198 |
my $image = Graphics::Magick->new; |
200 |
my $image = Graphics::Magick->new; |
Lines 211-217
foreach my $item (@{$items}) {
Link Here
|
211 |
my $alt_width = ceil($image->Get('width')); # the rounding up is important: Adobe reader does not handle long decimal numbers well |
213 |
my $alt_width = ceil($image->Get('width')); # the rounding up is important: Adobe reader does not handle long decimal numbers well |
212 |
my $alt_height = ceil($image->Get('height')); |
214 |
my $alt_height = ceil($image->Get('height')); |
213 |
my $ratio = $alt_width / $alt_height; |
215 |
my $ratio = $alt_width / $alt_height; |
214 |
my $display_height = ceil($images->{$_}->{'Dx'}); |
216 |
my $display_height = ceil($images->{$card_image}->{'Dx'}); |
215 |
my $display_width = ceil($ratio * $display_height); |
217 |
my $display_width = ceil($ratio * $display_height); |
216 |
|
218 |
|
217 |
|
219 |
|
Lines 219-238
foreach my $item (@{$items}) {
Link Here
|
219 |
$image->Set(magick => 'jpg', quality => 100); |
221 |
$image->Set(magick => 'jpg', quality => 100); |
220 |
|
222 |
|
221 |
# Write param for downsizing in pdf |
223 |
# Write param for downsizing in pdf |
222 |
$images->{$_}->{'scale'} = $pdf_scale_factor; |
224 |
$images->{$card_image}->{'scale'} = $pdf_scale_factor; |
223 |
|
225 |
|
224 |
# Write params for alt image... |
226 |
# Write params for alt image... |
225 |
$images->{$_}->{'alt'}->{'Sx'} = $oversize_factor * $alt_width; |
227 |
$images->{$card_image}->{'alt'}->{'Sx'} = $oversize_factor * $alt_width; |
226 |
$images->{$_}->{'alt'}->{'Sy'} = $oversize_factor * $alt_height; |
228 |
$images->{$card_image}->{'alt'}->{'Sy'} = $oversize_factor * $alt_height; |
227 |
$images->{$_}->{'alt'}->{'data'} = $alt_image->ImageToBlob(); |
229 |
$images->{$card_image}->{'alt'}->{'data'} = $alt_image->ImageToBlob(); |
228 |
|
230 |
|
229 |
# Write params for display image... |
231 |
# Write params for display image... |
230 |
$images->{$_}->{'Sx'} = $oversize_factor * $display_width; |
232 |
$images->{$card_image}->{'Sx'} = $oversize_factor * $display_width; |
231 |
$images->{$_}->{'Sy'} = $oversize_factor * $display_height; |
233 |
$images->{$card_image}->{'Sy'} = $oversize_factor * $display_height; |
232 |
$images->{$_}->{'data'} = $image->ImageToBlob(); |
234 |
$images->{$card_image}->{'data'} = $image->ImageToBlob(); |
233 |
|
235 |
|
234 |
my $err = $patron_card->draw_image($pdf); |
236 |
my $err = $patron_card->draw_image($pdf); |
235 |
warn sprintf ("Error encountered while attempting to draw image %s, %s", $_, $err) if $err; |
237 |
warn sprintf ("Error encountered while attempting to draw image %s, %s", $card_image, $err) if $err; |
|
|
238 |
# Destory all Graphics::Magick objects and related references |
239 |
# or bad things will happen. |
240 |
undef $image; |
241 |
undef $alt_image; |
242 |
undef $binary_data; |
236 |
} |
243 |
} |
237 |
$patron_card->draw_text($pdf); |
244 |
$patron_card->draw_text($pdf); |
238 |
} |
245 |
} |
239 |
- |
|
|