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