Business-Colissimo
view release on metacpan or search on metacpan
lib/Business/Colissimo.pm view on Meta::CPAN
return join(' ', substr($barcode, 0, 3),
substr($barcode, 3, 5),
substr($barcode, 8, 6),
substr($barcode, 14, 4),
substr($barcode, 18, 6));
}
}
else {
$parcel_number = $self->parcel_number;
$barcode .= $parcel_number;
$barcode .= $self->control_key($parcel_number);
if ($self->{international} && $type eq 'tracking') {
$barcode .= 'FR';
}
if ($args{spacing}) {
if ($self->{international}) {
return join(' ', substr($barcode, 0, 2),
substr($barcode, 2, 4),
substr($barcode, 6, 4),
substr($barcode, 10, 3));
}
else {
return join(' ', substr($barcode, 0, 2),
substr($barcode, 2, 5),
substr($barcode, 7, 5),
substr($barcode, 12, 1));
}
}
}
return $barcode;
}
=head2 barcode_image
Produces PNG image for tracking barcode:
$colissimo->barcode_image('tracking');
Produces PNG image for sorting barcode:
$colissimo->barcode_image('sorting');
Produces PNG image for arbitrary barcode:
$colissimo->barcode_image('8L20524752032');
The scale of the image can be changed for each
barcode individually:
$colissimo->barcode_image('8L20524752032', scale => 2);
The default scale is set to 1, because that produces
images with the right number of pixels to include them
into PDF with L<PDF::API2>, which uses 72dpi resolution
for images unless you specify width and height explicitly
(see L<PDF::API2::Content>).
The formula for calculating width in mm for a 72dpi
resolution is as follows:
(1px * 25.4) / 72dpi
This fits into Colissimo's requirement for the basic
module (narrowest element of the bar code) of
0.33 to 0.375 mm.
=cut
sub barcode_image {
my ($self, $type, %args) = @_;
my ($barcode, $image, $code128, $png, $scale, $height, $padding);
if ($type eq 'tracking' || $type eq 'sorting') {
$barcode = $self->barcode($type);
}
else {
$barcode = $type;
}
$code128 = Barcode::Code128->new;
$code128->border(0);
# scale
if ($scale = $self->{scale} || $args{scale}) {
$code128->scale($scale);
}
# height
if ($height = $self->{height} || $args{height}) {
$code128->height($height);
}
# padding
$padding = $self->{padding} || $args{padding};
$code128->padding($padding);
$code128->show_text(0);
$png = $code128->png($barcode);
}
=head2 logo
Returns logo file name for selected service.
$colissimo->logo;
=cut
sub logo {
my $self = shift;
return $logo_files{$self->{mode}} . '.bmp';
}
=head2 test
( run in 0.633 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )