Giter Club home page Giter Club logo

barcode's Introduction

barcode.php

Generate barcodes from a single PHP file. MIT license.

  • Output to PNG, GIF, JPEG, or SVG.
  • Generates UPC-A, UPC-E, EAN-13, EAN-8, Code 39, Code 93, Code 128, Codabar, ITF, QR Code, and Data Matrix.

Use directly as a PHP script with GET or POST:

barcode.php?f={format}&s={symbology}&d={data}&{options}

e.g.

barcode.php?f=png&s=upc-e&d=06543217
barcode.php?f=svg&s=qr&d=HELLO%20WORLD&sf=8&ms=r&md=0.8

When using this method, you must escape non-alphanumeric characters with URL encoding, for example %26 for & or %2F for ?.

Or use as a library from another PHP script:

include 'barcode.php';

$generator = new barcode_generator();

/* Output directly to standard output. */
header("Content-Type: image/$format");
$generator->output_image($format, $symbology, $data, $options);

/* Create bitmap image and write to standard output. */
header('Content-Type: image/png');
$image = $generator->render_image($symbology, $data, $options);
imagepng($image);
imagedestroy($image);

/* Create bitmap image and write to file. */
$image = $generator->render_image($symbology, $data, $options);
imagepng($image, $filename);
imagedestroy($image);

/* Generate SVG markup and write to standard output. */
header('Content-Type: image/svg+xml');
$svg = $generator->render_svg($symbology, $data, $options);
echo $svg;

/* Generate SVG markup and write to file. */
$svg = $generator->render_svg($symbology, $data, $options);
file_put_contents($filename, $svg);

When using this method, you must NOT use URL encoding.

Options:

f - Format. One of:

    png
    gif
    jpeg
    svg

s - Symbology (type of barcode). One of:

    upc-a          code-39         qr     dmtx
    upc-e          code-39-ascii   qr-l   dmtx-s
    ean-8          code-93         qr-m   dmtx-r
    ean-13         code-93-ascii   qr-q   gs1-dmtx
    ean-13-pad     code-128        qr-h   gs1-dmtx-s
    ean-13-nopad   codabar                gs1-dmtx-r
    ean-128        itf

d - Data. For UPC or EAN, use * for missing digit. For Codabar, use ABCD or ENT* for start and stop characters. For QR, encode in Shift-JIS for kanji mode.

w - Width of image. Overrides sf or sx.

h - Height of image. Overrides sf or sy.

sf - Scale factor. Default is 1 for linear barcodes or 4 for matrix barcodes.

sx - Horizontal scale factor. Overrides sf.

sy - Vertical scale factor. Overrides sf.

p - Padding. Default is 10 for linear barcodes or 0 for matrix barcodes.

pv - Top and bottom padding. Default is value of p.

ph - Left and right padding. Default is value of p.

pt - Top padding. Default is value of pv.

pl - Left padding. Default is value of ph.

pr - Right padding. Default is value of ph.

pb - Bottom padding. Default is value of pv.

bc - Background color in #RRGGBB format.

cs - Color of spaces in #RRGGBB format.

cm - Color of modules in #RRGGBB format.

tc - Text color in #RRGGBB format. Applies to linear barcodes only.

tf - Text font for SVG output. Default is monospace. Applies to linear barcodes only.

ts - Text size. For SVG output, this is in points and the default is 10. For PNG, GIF, or JPEG output, this is the GD library built-in font number from 1 to 5 and the default is 1. Applies to linear barcodes only.

th - Distance from text baseline to bottom of modules. Default is 10. Applies to linear barcodes only.

ms - Module shape. One of: s for square, r for round, or x for X-shaped. Default is s. Applies to matrix barcodes only.

md - Module density. A number between 0 and 1. Default is 1. Applies to matrix barcodes only.

wq - Width of quiet area units. Default is 1. Use 0 to suppress quiet area.

wm - Width of narrow modules and spaces. Default is 1.

ww - Width of wide modules and spaces. Applies to Code 39, Codabar, and ITF only. Default is 3.

wn - Width of narrow space between characters. Applies to Code 39 and Codabar only. Default is 1.

barcode's People

Contributors

cwchristerw avatar rebeccargb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

barcode's Issues

Text and barre code different

HI,

I would like make barre code with 1PUSBRS485F1.8M but only write USBRS485F1.8M texte ?

Is it possiblz to make that ?

Thank by advance
Eric

Coding Standard

Just wondering what's the intended coding standard (if there is one) just so I can run phpcs and know my pull request(s) matches.
Thanks!
Nick

Code 128 Error with "+" Symbol

Hello,

I got some errors with my code 128 barcode.
I am using it for openssl strings, and if in this string a "+" Symbol occures it just doesn't occure in the barcode picture.

As far as I know the barcode 128 should allow the + Symbol.
I would need some help. Thank you.

FYI:
I am Using not the class as a class. I am using the httpurl to create the image.

Аztec format generation

Good evening.

Not so long ago, I accidentally discovered your script for creating barcodes: https://github.com/kreativekorp/barcode
He is simply the best !!! I spent a lot of time searching, better than your script simply does not exist!
Very happy, very convenient to use, works very reliable and good!

There is only one wish. Please, maybe you could add aztec format generation to your script ?! This format is gaining popularity, and nowhere on the Internet is there an implementation of this format in the PHP language.
Please, if possible, add support for this format in your super cool script!

Mikhail Isaev (Belarus)

UCC-128 ?

Which of symbols in class is equivalent to UCC-128 ?

Multiple fnc1 in ean128 support

First, Thank you for this great library.

I edited your code and add fnc1 to show multiple piece of data in one barcode. But before the special character (fnc1) when the numbers are even it works. When the number is odd, it shows (24) instead of 8. (Ascii code) . Can you please help me to solve this issue

file extension

When i want to download my barcode its downloading as barcode.PHP. so this file extension may not effect us but there are other people who don't know how to change file extension. so add this line inside function output_image
for example:
case "png":
header('Content-Disposition: attachment; filename="anything.png"');

Member function on null

I'm doing this:

include('barcode.php');
$generator = new barcode_generator();
$svg = $generator->render_svg('code-128', '13123');
echo $svg;

And I'm getting this error:
Uncaught Error: Call to a member function render_svg() on null
If I do a var_dump($generator); just get NULL

I can't scan the ean 13 code

I can't scan the produced ean-13 barcode. This is my code:

`include 'barcode.php';

$format = 'png';
$symbology = 'ean-13-pad';
$data = '978020137963';
$options = '';

$generator = new barcode_generator();

$name = "test";

/* Create bitmap image. */

$image = $generator->render_image($symbology, $data, $options);
header( "Content-type: image/png" );
imagepng($image);
$save = strtolower($name) .".png";
chmod($save,0755);
imagepng($image, $save, 0, NULL);
imagedestroy($image);
`

First of all thank you for the great library. I am having a problem generating image file

First and foremost, it's a great library - Thank you.

I am having a bit problem.

When I call the barcode.php file using GET or POST: i.e. https://..../barcode.php?f=png&s=upc-a&d=213...410945 I am getting the png image. All looks good.

However, when I try to create an image (png, gif or jpg) using:
$image = $generator->render_image($symbology, $data, $options);
imagepng($image);
imagedestroy($image);

I get this: "�PNG � IHDR�d������ pHYs������+���-IDATx����n�0EQ\����}��8� ���ZR���0��0)��:A�����}DA��A��Q�DA��A��Q��FQJ��پ�u��g�[n{v���Ό{�xG�_[w�=[�5�Q�"

I did some reading and it looks like this issue could possibly be due to [UTF8 BOM] output. And I am not sure how to get No-BOM UTF8 output.

I would much appreciate any help.

Thank you in advance.

Kind regards.

width, height image problem

How to set width and height image. I try to set &w and &h params and don't work.

Examples:

<img src="barcode.php?f=png&s=ean-13&d=1111111111111&w=113&h=56" />
<img src="barcode.php?f=png&s=ean-13&d=1111111111111&w=113&h=56" width="113" height="56" />

Both code I add to PDF through mPDF library

how to save barcode img

Hello, how can I save generated barcode as image into file? Is this possible? Or Can I use generated barcode with dompdf? Thank you.

breaks by using --> * <-- for check Digit

Hallo,

/* Replace * with missing or check digit. /
->(-) while (($o = st(rr)pos($data, '
')) !== false) {
->(+) while (($o = st(r)pos($data, '*')) !== false) {

->(-) for ($i = 0; $i < 13; $i++) {
->(+) for ($i = 0; $i < ($o or 12); $i++) {

breaks by --> * <--
for ($i = 0; $i < (-->13<--); $i++) {
0 1 2 3 4 5 6 7 8 9 10 11 *
" < 13 must be < 12 "

or with while loop: use --> " < $o " <--:
if there is more than one --> * <--
search with --> st(r)pos(...) <-- for first occurrence and
use --> " < $o instead < 12 " <-- for position

hide text in barcode

I want to hide barcode text in bottom. Only barcode should display....how to do that?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.