Eric Belair
Eric Belair

Reputation: 10692

Why is the Barbecue Barcode library generating a different image from other Barcode generators?

I am having a problem with the Barbecue Barcode Library. I am trying to create a simple code128 barcode, but the image I get is different from what I get from other online (i.e. http://barcode-generator.org) and desktop (i.e. Zing) Barcode generators.

Here is the ColdFusion code I am using:

<cfscript>
    LOCAL.BarcodeData = "10047846";
    LOCAL.BarcodeFactory = CreateObject("java", "net.sourceforge.barbecue.BarcodeFactory");
    LOCAL.Barcode = LOCAL.BarCodeFactory.createCode128(LOCAL.BarcodeData);
    LOCAL.BarcodeImageHandler = CreateObject("java", "net.sourceforge.barbecue.BarcodeImageHandler");
    LOCAL.BarcodeBufferedImage = LOCAL.BarcodeImageHandler.getImage(LOCAL.Barcode);
    LOCAL.BarcodeImage = ImageNew(LOCAL.BarcodeBufferedImage);
    LOCAL.BarcodeImagePath =
        "C:\temp_\barcode-" & LOCAL.BarcodeData & ".jpg";
    ImageWrite(LOCAL.BarcodeImage, LOCAL.BarcodeImagePath, 1);
</cfscript>
<cfimage action="writeToBrowser" source="#LOCAL.BarcodeImagePath#" />

This outputs the following image:

Barbecue-generated Barcode 10047846

Yet, here is what I get from the Zing desktop program:

enter image description here

And here is what I get from barcode-generator.org:

enter image description here

Now, I have no issue with the sizing, scaling, etc. But, you can easily tell that the Barbecue-generated image is much different - simply look at the first several bars.

Why is this happening? Is this a Barbecue bug or am I doing something wrong?

Upvotes: 3

Views: 3118

Answers (3)

Eric Belair
Eric Belair

Reputation: 10692

Not sure this is the "answer", per se, but, when I changed the code to use the Code128C format, the image came out as expected. I just had to do some resizing to get it exactly the size I needed:

enter image description here

Code:

<cfscript>
    LOCAL.BarcodeData = "10047846";
    LOCAL.BarcodeFactory = CreateObject("java", "net.sourceforge.barbecue.BarcodeFactory");
    LOCAL.Barcode = LOCAL.BarCodeFactory.createCode128C(LOCAL.BarcodeData);
    LOCAL.Barcode.setDrawingText(false);
    LOCAL.Barcode.setDrawingQuietSection(false);
    LOCAL.Barcode.setBarWidth(1);
    LOCAL.Barcode.setBarHeight(30);
    LOCAL.BarcodeImageHandler = CreateObject("java", "net.sourceforge.barbecue.BarcodeImageHandler");
    LOCAL.BarcodeBufferedImage = LOCAL.BarcodeImageHandler.getImage(LOCAL.Barcode);
    LOCAL.BarcodeImage = ImageNew(LOCAL.BarcodeBufferedImage);
    LOCAL.BarcodeImagePath =
        "C:\temp_\barcode-" & LOCAL.BarcodeData & ".jpg";
    ImageWrite(LOCAL.BarcodeImage, LOCAL.BarcodeImagePath, 1);
</cfscript>
<cfimage action="writeToBrowser" source="#LOCAL.BarcodeImagePath#" />

Upvotes: 1

Chester
Chester

Reputation: 1083

I scanned it with a barcode scanner and all three images read the same string "10047846". For barcodes, I use CFBarbecue (http://cfbarbecue.riaforge.org/), a ColdFusion wrapper for Barbecue. Using the same string, below is the image I was able to generate using CFBarbecue.

enter image description here

Upvotes: 0

Twillen
Twillen

Reputation: 1466

It looks like the bar width of your image is larger then the examples. Set the bar width to 1 px. by adding LOCAL.Barcode.setBarWidth(1);before you generate the barcode.

<cfscript>
  LOCAL.BarcodeData = "10047846";
  LOCAL.BarcodeFactory = CreateObject("java", "net.sourceforge.barbecue.BarcodeFactory");
  LOCAL.Barcode = LOCAL.BarCodeFactory.createCode128(LOCAL.BarcodeData);
  LOCAL.Barcode.setBarWidth(1); // decrease the width of the bars
  LOCAL.Barcode.setBarHeight(50); // if you want a taller barcode like the examples
  LOCAL.BarcodeImageHandler = CreateObject("java", "net.sourceforge.barbecue.BarcodeImageHandler");
  LOCAL.BarcodeBufferedImage = LOCAL.BarcodeImageHandler.getImage(LOCAL.Barcode);
  LOCAL.BarcodeImage = ImageNew(LOCAL.BarcodeBufferedImage);
  LOCAL.BarcodeImagePath = gettempDirectory()& "\barcode-" & LOCAL.BarcodeData & ".jpg";
ImageWrite(LOCAL.BarcodeImage, LOCAL.BarcodeImagePath, 1);
</cfscript>

Upvotes: 0

Related Questions