Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
laziness, impatience, and hubris
 
PerlMonks

help with Barcode::Code128

by djbryson (Beadle)
 | Log in | Create a new user | The Monastery Gates | Super Search | 
 | Seekers of Perl Wisdom | Meditations | PerlMonks Discussion | 
 | Obfuscation | Reviews | Cool Uses For Perl | Perl News | Q&A | Tutorials | 
 | Poetry | Recent Threads | Newest Nodes | Donate | What's New | 

on Nov 06, 2009 at 15:44 UTC ( #805508=perlquestion: print w/ replies, xml ) Need Help??
djbryson has asked for the wisdom of the Perl Monks concerning the following question:

Trying to generate a PNG barcode. Script receives a random interger and converts to a barcode image. It also has to be 128A. I tried switching FNC1 to CodeA. I always get the same barcode image for my ouput. I need to encode the $text var right? I commented out use gd; because it generates the image either way.

use strict; #use gd; print "\nRunning Barcode... \n\n"; my $text = "333"; use Barcode::Code128 'FNC1'; my $object = new Barcode::Code128; $object->text(FNC1.'00000123455555555558'); $object->png($text); open(PNG, ">h:/perl/code128.png") or die "Can't write code128.png: $!\ +n"; binmode(PNG); print PNG $object->png("CODE 128"); close(PNG);

Comment on help with Barcode::Code128
Download Code
Re: help with Barcode::Code128
by gmargo (Pilgrim) on Nov 06, 2009 at 16:54 UTC

    I am confused about what you are looking for. You are setting the text to encode three different times, and generating two separate images, although you only save the last one to a file. That last one has a fixed string ("CODE 128") so you should be getting the same .png file each time.

    Here's some quick-n-dirty code that produces three barcodes with different integer texts, hope it can help you.

    #/usr/bin/perl use strict; use warnings; use diagnostics; use Barcode::Code128; my $times = 3; print "Running Barcode... encoding $times random integers\n"; my $object = Barcode::Code128->new(); $object->code('A'); # Enforce 128A? srand(0); # More interested in repeatability than randomness foreach (1 .. $times) { my $text = ""; # Make up a 10-digit decimal number $text .= "".int(rand(10)) foreach (1 .. 10); my $filename = "code128_".$_.".png"; open(my $png, ">", $filename) || die("Cannnot open $filename: $!") +; binmode($png); print $png $object->png($text); close($png); print "Text \"$text\" encoded in file $filename\n"; }

[reply]
[d/l]

Back to Seekers of Perl Wisdom


Login:
Password
remember me
What's my password?
Create A New User

Node Status
node history
Node Type: perlquestion [id://805508]
Approved by wfsp
Front-paged by wfsp
help
Community Ads
Chatterbox
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users
Others romping around the Monastery: (12)
GrandFather
wfsp
atcroft
herveus
Eyck
clinton
NodeReaper
djp
$self
vishi83
gnosti
im2
As of 2009-11-21 09:46 GMT
Sections
The Monastery Gates
Seekers of Perl Wisdom
Meditations
PerlMonks Discussion
Categorized Q&A
Tutorials
Obfuscated Code
Perl Poetry
Cool Uses for Perl
Perl News
Information
PerlMonks FAQ
Guide to the Monastery
What's New at PerlMonks
Voting/Experience System
Tutorials
Reviews
Library
Perl FAQs
Other Info Sources
Find Nodes
Nodes You Wrote
Super Search
List Nodes By Users
Newest Nodes
Recently Active Threads
Selected Best Nodes
Best Nodes
Worst Nodes
Saints in our Book
Leftovers
The St. Larry Wall Shrine
Offering Plate
Awards
Craft
Snippets Section
Code Catacombs
Quests
Editor Requests
Buy PerlMonks Gear
PerlMonks Merchandise
Planet Perl
Perlsphere
Use Perl
Perl.com
Perl 5 Wiki
Perl Jobs
Perl Mongers
Perl Directory
Perl documentation
CPAN
Random Node
Voting Booth

Future historians will find that the material characteristic of the current era is...

Aluminium
Plastic
Oil
Water
Carbon dioxide
Copper
Iron
Silicon
Salt
Uranium
Hydrogen
Other

Results (729 votes), past polls