- Saved searches
- Use saved searches to filter your results more quickly
- License
- theel0ja/php-barcode
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
- Saved searches
- Use saved searches to filter your results more quickly
- License
- rlt3/php-barcode
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
- Manual — EAN-13
- Example
- Methods
- BCGean13’s Methods
- BCGBarcode1D’s Methods
- BCGBarcode’s Methods
- Code Example
- Method explanations
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
Barcode generator, based on Folke Ashberg’s php-barcode.
License
theel0ja/php-barcode
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
- Barcode-Images using libgd (png, jpg,gif),
- HTML-Images (using 1×1 pixel and html-table)
- silly Text-Barcodes
PHP-Barcode encodes using
- a built-in EAN-13/ISBN Encoder
- genbarcode (by Folke Ashberg), a command line barcode-encoder which uses GNU-Barcode genbarcode can encode EAN-13, EAN-8, UPC, ISBN, 39, 128(a,b,c), I25, 128RAW, CBR, MSI, PLS genbarcode is available at www.ashberg.de/php-barcode
(C) 2001, 2002, 2003, 2004, 2011 by Folke Ashberg folke@ashberg.de
The newest version can be found at http://www.ashberg.de/php-barcode
WHAT YOU NEED TO BE ABLE TO USE PHP-BARCODE
- You need php>4 on your system.
- You need the gd2-extension to be able to render images.
- You need a TrueTypeFont if you want to see the CODE below the bars.
- You need genbarcode (from www.ashberg.de/php-barcode) in you want to use another encoding than EAN-12/EAN-12/ISBN
Copy the following files into your html/php-directory
- php-barcode.php — main library
- encode_bars.php — built-in encoders optional:
- barcode.php — Sample-File
- white.png — for HTML-Images
- black.png — for HTML-Images
UNIX: A TrueTypeFont isn't included in this distribution! Copy one into the html/php-directory and change in php-barcode.php $font_loc (change the arialbd.tff to your font name). arialbd.ttf from Windows looks great. WINDOWS: If you use Windows the font should be located automatically.
If you want to generate not only EAN-12/EAN-13/ISBN-Codes you have to install genbarcode, a small unix-commandline tool which uses GNU-Barcode. genbarcode is available http://www.ashberg.de/php-barcode , read genbarcodes README for installation. If you have installed genbarcode not to /usr/bin set the $genbarcode_loc in php-barcode.php .
If everything works fine you should see an image if you call http://localhost/path/barcode.php Or call http://localhost/path/barcode.php?code=&encoding=&mode=&size=
If you need more then the sample barcode.php can do, you need to build your own.
function barcode_encode(code, encoding) encodes $code with $encoding using genbarcode OR built-in encoder if you don’t have genbarcode only EAN-13/ISBN is possible
You can use the following encodings (when you have genbarcode):
ANY | choose best-fit (default) |
EAN | 8 or 13 EAN-Code |
Pipe | $1 |
UPC | 12-digit EAN |
ISBN | isbn numbers (still EAN-13) |
39 | code 39 |
128 | code 128 (a,b,c: autoselection) |
128C | code 128 (compact form for digits) |
128B | code 128, full printable ascii |
I25 | interleaved 2 of 5 (only digits) |
128RAW | Raw code 128 (by Leonid A. Broukhis) |
CBR | Codabar (by Leonid A. Broukhis) |
MSI | MSI (by Leonid A. Broukhis) |
PLS | Plessey (by Leonid A. Broukhis) |
- array[encoding] : the encoding which has been used
- array[bars] : the bars
- array[text] : text-positioning info
function barcode_outimage(text, bars [, scale [, mode [, total_y [, space ]]]] )
Outputs an image using libgd
text | the text-line (:: . ) |
bars | where to place the bars (. ) |
scale | scale factor ( 1 < scale < unlimited (scale 50 will produce 5400x300 pixels when using EAN-13. )) |
mode | png,gif,jpg, depending on libgd ! (default=’png’) |
total_y | the total height of the image ( default: scale * 60 ) |
space | space |
default: |
---|
$space[top] = 2 * $scale; |
$space[bottom]= 2 * $scale; |
$space[left] = 2 * $scale; |
$space[right] = 2 * $scale; |
function barcode_outhtml(text, bars [, scale [, total_y [, space ]]] )
returns(!) HTML-Code for barcode-image using html-code (using a table and with black.png and white.png)
text |
bars |
scale |
total_y |
space |
default: |
---|
$space[top] = 2 * $scale; |
$space[bottom]= 2 * $scale; |
$space[left] = 2 * $scale; |
$space[right] = 2 * $scale; |
function barcode_outtext(code, bars)
Returns (!) a barcode as plain-text
ATTENTION: this is very silly!
text | the text-line (:: . ) |
bars | where to place the bars (. ) |
Also see barcode.php or just use them 🙂
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
About
Barcode generator, based on Folke Ashberg’s php-barcode.
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
License
rlt3/php-barcode
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
This is a re-working of php-barcode by Folke Ashberg. Currently, my version only creates EAN-13 barcodes, however I plan to make the source modular to allow for additions of ISBN, Code 12, and others.
Folke did a lot of good work, but it is nigh unreadable, I think, and I wanted to fix that. Because of this, too, it is really hard to add newer barcode types.
I also needed an on-the-fly barcode solution for a freelance job. This code has been in production for several years.
The signatures are fairly simple. Simply call barcode with the number of the barcode and the scale of the barcode as an integer. The number needs to be either 12 or 13 digits. The barcode will always be 13 digits even if only 12 are supplied as the 13th digit is the checksum of the first 12. The barcode’s scale will not go lower than 2 for scaling reasons and no higher than 12 for memory reasons. A scale of 4 has worked well for my purposes in the past.
$barcode = new Barcode(1349875921348, 4); $barcode = new Barcode(439457143245, 10);
The key thing to keep up with is the FreeSansBold.ttf file. By default the Barcode class will look into PHP’s calling directory for the font file. You can specify a path as a third parameter.
$barcode = new Barcode(123456789120, 4, "/path/to/FreeSansBold.ttf");
There are only two public methods: image() and display() . The first function image() returns the PHP created image as a reference. This may be used to save an image to file, e.g. imagepng($barcode->image(), «/path/to/storage/barcode.png») . The second function display() simply calls the correct headers and displays the barcode in the browser. Useful for debugging.
About
Manual — EAN-13
EAN-13 code allows you to encode values to sell products. This code contains 13 numbers but since the last character is a checksum, you must enter only 12 characters. You can enter 13 characters, the last number will be replaced if it doesn’t match the right checksum.
This class inherits the BCGBarcode1D class.
Example
Methods
BCGean13’s Methods
BCGBarcode1D’s Methods
- getThickness() — Returns the thickness of the barcode
- setThickness( $thickness ) — Specifies the thickness of the barcode
- getLabel() — Gets the label
- setLabel( $label ) — Sets the label
- getFont() — Gets the text font for the label
- setFont( $font ) — Sets the text font for the label
- getChecksum() — Gets the checksum appended to the barcode
- setDisplayChecksum( $display ) — Specifies the checksum to be added to the label
BCGBarcode’s Methods
- parse( $text ) — Analyzes a $text message to draw afterwards
- draw( $image ) — Draws the barcode on the $image
- getDimension( $width , $height ) — Returns an array containing the required size for the image
- getScale() — Gets the scale of the barcode
- setScale( $scale ) — Sets the scale of the barcode
- getForegroundColor() — Gets the color of the bars
- setForegroundColor( $color ) — Sets the color of the bars
- getBackgroundColor() — Gets the color of the spaces
- setBackgroundColor( $color ) — Sets the color of the spaces
- setColor( $foregroundColor , $backgroundColor ) — Sets the color of the bars and spaces
- getOffsetX() — Gets the X offset
- setOffsetX( $value ) — Sets the X offset
- getOffsetY() — Gets the Y offset
- setOffsetY( $value ) — Sets the Y offset
- addLabel( $label ) — Adds a label to the graphic
- removeLabel( $label ) — Removes a label from the graphic
- clearLabels() — Removes the labels from the graphic
Code Example
use BarcodeBakery\Common\BCGFontFile;
use BarcodeBakery\Common\BCGColor;
use BarcodeBakery\Common\BCGDrawing;
use BarcodeBakery\Barcode\BCGean13;
$font = new BCGFontFile(__DIR__ . '/font/Arial.ttf', 18);
$colorBlack = new BCGColor(0, 0, 0);
$colorWhite = new BCGColor(255, 255, 255);
// Barcode Part
$code = new BCGean13();
$code->setScale(2);
$code->setThickness(30);
$code->setForegroundColor($colorBlack);
$code->setBackgroundColor($colorWhite);
$code->setFont($font);
$code->parse('578124871412');
// Drawing Part
$drawing = new BCGDrawing($code, $colorWhite);
header('Content-Type: image/png');
$drawing->finish(BCGDrawing::IMG_FORMAT_PNG);
?>