Barcode with ImageMagick

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
immortal26

Barcode with ImageMagick

Post by immortal26 »

I've been googling my "butt" off on finding a good barcode generator but most of them just don't work right or not the way I want them to.
There is a nice a php script that uses the GD library but it's a little slow for what I need.
Just curious if there is a pure script out there that someone has made that uses ImageMagick and ImageMagick alone.
If one can be made with GD lib I'm sure there should be "something" out there using pure ImageMagick... be it shell/bash/perl script whatever.

Thanks.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Barcode with ImageMagick

Post by el_supremo »

This isn't as "pure" as I think you are looking for but I've used some free barcode fonts with IM. For example, I installed this one
http://www.idautomation.com/fonts/free/
and the following command (I'm using Windows XP) creates a barcode image

Code: Select all

convert -font IDAutomationHC39M -pointsize 24 -fill black -size 400x100 xc:white -draw "text 20,80 '*3456*'" barcode.png
and the zbar program correctly decodes it:

Code: Select all

"C:/program files/zbar/bin/zbarimg" -q --raw barcode.png
3456
Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Barcode with ImageMagick

Post by anthony »

I have added this to the "Symbol Fonts" section of "Text to Image Handling of IM Examples
http://www.imagemagick.org/Usage/text/#symbol
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
immortal26

Re: Barcode with ImageMagick

Post by immortal26 »

That all looks great, actually perfect if I were to use that format for the barcode i need... but I need code 128... and with a demo from idautomation this is what I get:
A .rtf with vb functionality (assumingly for other programs to use)

Code: Select all

'  Visual Basic & VBA Functions for IDAutomation Universal Fonts V7.12

'  © Copyright, 2000-2007 IDAutomation.com, Inc. All rights reserved.

'  Redistribution and use of this code in source and/or binary

'  forms, with or without modification, are permitted provided

'  that: (1) all copies of the source code retain the above

'  unmodified copyright notice and this entire unmodified

'  section of text, (2) You or Your organization owns a valid

'  Developer License to this product from IDAutomation.com

'  and, (3) when any portion of this code is bundled in any

'  form with an application, a valid notice must be provided

'  within the user documentation, start-up screen or in the

'  help-about section of the application that specifies

'  IDAutomation.com as the provider of the Software bundled

'  with the application.

'*****************************************************************

Private I As Integer
Private J As Integer
Private DataToPrint As String
Private OnlyCorrectData As String
Private Encoding As String
Private WeightedTotal As Long
Private WeightValue As Integer
Private CurrentValue As Long
Private CheckDigitValue As Integer
Private Factor As Integer
Private CheckDigit As Integer
Private CurrentEncoding As String
Private NewLine As String
Private CurrentChar As String
Private CurrentCharNum As Integer
Private C128_StartA As String
Private C128_StartB As String
Private C128_StartC As String
Private C128_Stop As String
Private C128Start As String
Private C128CheckDigit As String
Private StartCode As String
Private StopCode As String
Private LeadingDigit As Integer
Private EAN2AddOn As String
Private EAN5AddOn As String
Private EANAddOnToPrint As String
Private HumanReadableText As String
Private StringLength As Integer
Private Char1 As String
Private Char2 As String
Private nwPattern As String
Private CorrectFNC As Integer
Private Idx As Integer
Private PrintableString As String

'Symbology set Arrays
Private SetC128(106) As Variant
Private SetITF(10) As Variant
Private Set39(44) As Variant
Private SetCODABAR(20) As Variant
Private SetMSI(10) As Variant
Private SetPostnet(10) As Variant
Private SetPlanet(10) As Variant
'END OF DECLARATIONS

Public Function IDAutomation_Uni_C128b(DataToEncode As String) As String

    PrintableString = ""

SetC128(0) = "EFF"
SetC128(1) = "FEF"
SetC128(2) = "FFE"
SetC128(3) = "BBG"
SetC128(4) = "BCF"
SetC128(5) = "CBF"
SetC128(6) = "BFC"
SetC128(7) = "BGB"
SetC128(8) = "CFB"
SetC128(9) = "FBC"
SetC128(10) = "FCB"
SetC128(11) = "GBB"
SetC128(12) = "AFJ"
SetC128(13) = "BEJ"
SetC128(14) = "BFI"
SetC128(15) = "AJF"
SetC128(16) = "BIF"
SetC128(17) = "BJE"
SetC128(18) = "FJA"
SetC128(19) = "FAJ"
SetC128(20) = "FBI"
SetC128(21) = "EJB"
SetC128(22) = "FIB"
SetC128(23) = "IEI"
SetC128(24) = "IBF"
SetC128(25) = "JAF"
SetC128(26) = "JBE"
SetC128(27) = "IFB"
SetC128(28) = "JEB"
SetC128(29) = "JFA"
SetC128(30) = "EEG"
SetC128(31) = "EGE"
SetC128(32) = "GEE"
SetC128(33) = "ACG"
SetC128(34) = "CAG"
SetC128(35) = "CCE"
SetC128(36) = "AGC"
SetC128(37) = "CEC"
SetC128(38) = "CGA"
SetC128(39) = "ECC"
SetC128(40) = "GAC"
SetC128(41) = "GCA"
SetC128(42) = "AEK"
SetC128(43) = "AGI"
SetC128(44) = "CEI"
SetC128(45) = "AIG"
SetC128(46) = "AKE"
SetC128(47) = "CIE"
SetC128(48) = "IIE"
SetC128(49) = "ECI"
SetC128(50) = "GAI"
SetC128(51) = "EIC"
SetC128(52) = "EKA"
SetC128(53) = "EII"
SetC128(54) = "IAG"
SetC128(55) = "ICE"
SetC128(56) = "KAE"
SetC128(57) = "IEC"
SetC128(58) = "IGA"
SetC128(59) = "KEA"
SetC128(60) = "IMA"
SetC128(61) = "FDA"
SetC128(62) = "OAA"
SetC128(63) = "ABH"
SetC128(64) = "ADF"
SetC128(65) = "BAH"
SetC128(66) = "BDE"
SetC128(67) = "DAF"
SetC128(68) = "DBE"
SetC128(69) = "AFD"
SetC128(70) = "AHB"
SetC128(71) = "BED"
SetC128(72) = "BHA"
SetC128(73) = "DEB"
SetC128(74) = "DFA"
SetC128(75) = "HBA"
SetC128(76) = "FAD"
SetC128(77) = "MIA"
SetC128(78) = "HAB"
SetC128(79) = "CMA"
SetC128(80) = "ABN"
SetC128(81) = "BAN"
SetC128(82) = "BBM"
SetC128(83) = "ANB"
SetC128(84) = "BMB"
SetC128(85) = "BNA"
SetC128(86) = "MBB"
SetC128(87) = "NAB"
SetC128(88) = "NBA"
SetC128(89) = "EEM"
SetC128(90) = "EME"
SetC128(91) = "MEE"
SetC128(92) = "AAO"
SetC128(93) = "ACM"
SetC128(94) = "CAM"
SetC128(95) = "AMC"
SetC128(96) = "AOA"
SetC128(97) = "MAC"
SetC128(98) = "MCA"
SetC128(99) = "AIM"
SetC128(100) = "AMI"
SetC128(101) = "IAM"
SetC128(102) = "MAI"
SetC128(103) = "EDB"
SetC128(104) = "EBD"
SetC128(105) = "EBJ"

    WeightedTotal = 104

    PrintableString = SetC128(104)

    StringLength = Len(DataToEncode)

    For I = 1 To StringLength

         CurrentCharNum = (AscW(Mid(DataToEncode, I, 1))) - 32

         CurrentValue = CurrentCharNum * I

         WeightedTotal = WeightedTotal + CurrentValue

         PrintableString = PrintableString & SetC128(CurrentCharNum)

    Next I

    CheckDigitValue = (WeightedTotal Mod 103)

    PrintableString = PrintableString & SetC128(CheckDigitValue)

    'GIAH produces the stop character.

    IDAutomation_Uni_C128b = PrintableString & "GIAH"

    'SetC128 = Null

    DataToEncode = ""

End Function


'*****************************************************************

'  © Copyright, IDAutomation.com, Inc. All rights reserved.

'  Redistribution and use of this code in source and/or binary

'  forms, with or without modification, are permitted provided

'  that: (1) all copies of the source code retain the above

'  unmodified copyright notice and this entire unmodified

'  section of text, (2) You or Your organization owns a valid

'  Developer License to this product from IDAutomation.com

'  and, (3) when any portion of this code is bundled in any

'  form with an application, a valid notice must be provided

'  within the user documentation, start-up screen or in the

'  help-about section of the application that specifies

'  IDAutomation.com as the provider of the Software bundled

'  with the application.

'*****************************************************************

'Internal Version 2008.1.28
Can ImageMagick read this?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Barcode with ImageMagick

Post by snibgo »

As far as I know, ImageMagick can't read or do anything with RTF (Rich Text Format) or VB (Visual Basic).
snibgo's IM pages: im.snibgo.com
tonybrooks
Posts: 1
Joined: 2013-03-24T20:36:26-07:00
Authentication code: 6789

Re: Barcode with ImageMagick

Post by tonybrooks »

you said those barcode generator don't work right or not the way you want them to, so I wonder more details will help. Besides, there is a script on UPC-A barcode generation. Maybe it will help a little.


http://forum.swiftirc.net/viewtopic.php ... 03#p231403
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Barcode with ImageMagick

Post by anthony »

What code? It was a font!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply