GD-Barcode-Image
view release on metacpan or search on metacpan
--- #YAML:1.0
name: GD-Barcode-Image
version: 1.03
abstract: Script to create images of barcodes
license: ~
generated_by: ExtUtils::MakeMaker version 6.36
distribution_type: module
requires:
GD: 0
GD::Barcode: 0
Image::Magick: 0
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.2.html
version: 1.2
author:
- Avinash Chopde <avinash@acm.org>
Makefile.PL view on Meta::CPAN
use ExtUtils::MakeMaker;
use 5.005;
WriteMakefile(
'NAME' => 'GD::Barcode::Image',
'VERSION_FROM' => 'lib/GD/Barcode/Image.pm', # finds $VERSION
'EXE_FILES' => [ 'bin/barcodegen' ],
'ABSTRACT' => 'Script to create images of barcodes',
'AUTHOR' => 'Avinash Chopde <avinash@acm.org>',
'PREREQ_PM' => { 'GD::Barcode' => 0, 'GD' => 0, 'Image::Magick' => 0, },
);
NAME
GD::Barcode::Image - Create Image::Magick object for a barcode
barcodegen - Command-line utility to create barcode image files
DESCRIPTION
GD::Barcode::Image extends GD::Barcode and allows creation of
barcode images in Image::Magick format. Command-line script
barcodegen is also provided to create outputs in any format that
Image::Magick supports such as PDF, EPS, GIF, etc.
After installation, use perldoc to see detailed documentation:
perldoc GD::Barcode::Image
perldoc barcodegen
DEPENDS ON
This module requires these modules:
GD::Barcode
GD
Image::Magick
INSTALLATION
The module can be installed using the standard Perl procedure:
perl Makefile.PL
make
make test
make install # You may need to be root
make clean # or make realclean
bin/barcodegen view on Meta::CPAN
#!/usr/bin/perl -w
#
# barcodegen - a program for making barcodes in various image formats
#
# GD::Barcode::Image is the package that contains barcodegen
#
# uses GD::Barcode, supports following types of barcodes:
# Code39 COOP2of5 EAN13 EAN8 IATA2of5 Industrial2of5
# ITF Matrix2of5 NW7 QRcode UPCA UPCE
# Barcode info: http://www.makebarcode.com/specs/speclist.html
# For output images, uses Image::Magick - so output can be any format
# that Image::Magick supports. This requires the GD module also.
# -----------------------------------------------------------------------
# Created: May 2007
# Copyright (C) 2007 Avinash Chopde <avinash@aczoom.com> www.aczoom.com
# -----------------------------------------------------------------------
# License
# This program is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
# See http://www.perl.com/perl/misc/Artistic.html.
# -----------------------------------------------------------------------
use warnings;
use strict;
use Getopt::Long 2.33; # > 2.32 for --version flag
use Pod::Usage;
use GD::Barcode::Image;
use Image::Magick;
use Carp;
our $VERSION = 1.03;
# ---------------------------------------
my $man = 0;
my $help = 0;
my $verbose = 0;
my $type = 'Code39'; # barcode type (Code39, EAM13, UPCA etc)
my $format = 'PNG'; # output type (PNG, JPEG, EPS, PDF, etc)
bin/barcodegen view on Meta::CPAN
);
my $gdbcim = GD::Barcode::Image->new( $type, $text, \%rhPrm );
croak "** Error: Barcode $type failed for $text: ${GD::Barcode::errStr},"
unless ($gdbcim);
my $image = $gdbcim->plot_imagick( NoText => $notext, Height => $height );
croak "** Error: Barcode imaging failed: ${GD::Barcode::errStr},"
unless ($image);
# using Image::Magick, add optional border, and convert to required format
my $errStr;
$errStr = $image->Set( bordercolor => 'white' );
carp "Warning: \$image->Set bordercolor failed: $errStr,"
if ("$errStr");
if ($border) {
$errStr = $image->Border( geometry => $border );
carp "Warning: \$image->Border failed: $errStr,"
if ("$errStr");
}
bin/barcodegen view on Meta::CPAN
STDOUT, or written to a file.
All barcodes supported by the GD::Barcode Perl module can be handled, for
example:
Code39 COOP2of5 EAN13 EAN8 IATA2of5 Industrial2of5
ITF Matrix2of5 NW7 QRcode UPCA UPCE.
The default barcode type is Code39, and its character set includes
the digits 0-9, the letters A-Z (upper case only), and the following
symbols: space, minus (-), plus (+), period (.), dollar sign ($), slash
(/), and percent (%).
The barcode can be output in any format supported by the Image::Magick
perl module. The most common formats include: PNG, JPEG, GIF, EPS, PDF.
Pixel dimensions are used to specify the height and optional border.
Resolution of 72 pixels/inch may be assumed when needed - such as in the
PostScript output formats.
=head1 EXAMPLES
=over 8
bin/barcodegen view on Meta::CPAN
01234567890, with a text label that includes the checksum (which is 5 for
this barcode). Informational messages will also be printed to STDERR.
=back
=head1 PREREQUISITES
This script requires the following modules:
C<GD::Barcode>,
C<GD>,
C<Image::Magick>.
=head1 OSNAMES
any
=head1 SCRIPT CATEGORIES
Image/Utility
=cut
lib/GD/Barcode/Image.pm view on Meta::CPAN
package GD::Barcode::Image;
use strict;
use Image::Magick;
use GD::Barcode;
require Exporter;
use vars qw($VERSION @ISA $AUTOLOAD);
@ISA = qw(Exporter); # HAS-A GD::Barcode:<Symbology>, no IS-A
$VERSION = 1.03;
#------------------------------------------------------------------------------
# GD::Barcode::Image extends GD::Barcode functionality.
# GD/Barcode.pm is a package with a single factory-like method named new()
# new() itself creates objects of a specific Symbology - Barcode Type,
lib/GD/Barcode/Image.pm view on Meta::CPAN
# init (for GD::Barcode::Image)
# special check: since Image.pm resides in GD/Barcode, there is
# the danger that the GD::Barcode->new() function will load/init this
# module as a Barcode Symbology, so check for type
#------------------------------------------------------------------------------
sub init() {
return 'Error in init() - Invalid Barcode Type: "Image"';
}
#------------------------------------------------------------------------------
# plot_imagick: Convert to Image::Magick Object (for GD::Barcode)
# Requires both the GD and Image::Magick modules.
# signature is similar to GD::Barcode::QRcode->plot()
#------------------------------------------------------------------------------
sub plot_imagick($%) {
my ( $oThis, %hParam ) = @_;
#Create Image
my $imNew = undef;
eval {
require Image::Magick;
my ( $gdNew, $png ) = ( undef, undef );
$gdNew = $oThis->{gd_barcode}->plot(%hParam);
if ($gdNew) {
$png = $gdNew->png();
$imNew = Image::Magick->new();
$GD::Barcode::errStr = $imNew->BlobToImage($png);
$imNew = undef
if ($GD::Barcode::errStr); # on error, free imagick object
}
};
return $imNew;
}
#------------------------------------------------------------------------------
lib/GD/Barcode/Image.pm view on Meta::CPAN
my $gdbc = $oThis->{gd_barcode};
my $method = $AUTOLOAD;
$method =~ s/.*:://;
$method = $gdbc->can($method);
return $method ? $gdbc->$method(@_) : undef;
}
#------------------------------------------------------------------------------
=head1 NAME
GD::Barcode::Image - Create Image::Magick object for a barcode
=head1 SYNOPSIS
use GD::Barcode::Image;
my $oGdBarIm = GD::Barcode::Image->new( $type, $text, \%rhPrm );
die "** Error: Barcode $type failed for $text: ${GD::Barcode::errStr},"
unless ($oGdBarIm);
my $oGdIm = $oGdBarIm->plot_imagick( Height => I<pixels>, NoText => I<0 | 1>] );
lib/GD/Barcode/Image.pm view on Meta::CPAN
Constructor.
Creates a GD::Barcode::Image object for text I<$sTxt>, for barcode
symbology type I<$sType>.
Additional parameters can be provided for QRcode type - see
GD::Barcode::QRcode module in the GD::Barcode package.
=item plot_imagick()
I<$oGdIm> = $oGdBarIm->plot_imagick([Height => I<$iHeight>, NoText => I<0 | 1>]);
creates Image::Magick object for the barcode object.
I<$iHeight> is height of the image. If I<NoText> is 1, the image has no text image of I<$sTxt>.
Height and NoText parameters will not apply to the QRcode barcode type.
=item plot_gd()
I<$oGd> = $oGdBarIm->plot_gd([Height => I<$iHeight>, NoText => I<0 | 1>]);
Same as plot_imagick() except that a GD image object is returned.
=item $GD::Barcode::errStr
( run in 0.556 second using v1.01-cache-2.11-cpan-beeb90c9504 )