Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions license.txt → LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
Copyright (c) 2011 emberlabs.org
================================

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
11 changes: 5 additions & 6 deletions readme.md → README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Barcode Generator for PHP
=========================

Perhaps the biggest issue I encountered when creating an inventory management
system for a client was the fact that there was no unified framework for
system for a client was the fact that there was no unified framework for
barcode generation in PHP that was reasonable in price, much less Open Source.
I hope to fill this gaping hole in the market today with Barcode Generator for
PHP.
Expand All @@ -16,13 +16,12 @@ this library.
Usage
-----

I have an example index.php on gist. This assumes you have the repo cloned in include/ relative to the this index file:
[index.php](https://gist.github.com/1175098)
Use the ```example.php``` to test the barcodes.

Supported Codes
---------------

Some are planned, others are complete.
Some are planned, others are complete.

* Code39 **DONE**
* Code128 **DONE**
Expand All @@ -35,5 +34,5 @@ Contribute
----------

If you have something to add (maybe a new barcode) or just a bug fix, please
send me a pull request and I will be sure to respond or even merge it. I am
always looking for help with these projects, so don't be shy.
send me a pull request and I will be sure to respond or even merge it. I am
always looking for help with these projects, so don't be shy.
97 changes: 97 additions & 0 deletions example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
require __DIR__.'/src/BarcodeBase.php';
require __DIR__.'/src/QRCode.php';
require __DIR__.'/src/DataMatrix.php';
require __DIR__.'/src/Code39.php';
require __DIR__.'/src/Code128.php';

$bcode = array();

$bcode['qr'] = array('name' => 'QR Code', 'obj' => new emberlabs\Barcode\QRCode());
$bcode['dm'] = array('name' => 'DataMatrix', 'obj' => new emberlabs\Barcode\DataMatrix());
$bcode['c39'] = array('name' => 'Code39', 'obj' => new emberlabs\Barcode\Code39());
$bcode['c128'] = array('name' => 'Code128', 'obj' => new emberlabs\Barcode\Code128());

function bcode_error($m)
{
echo "<div class='error'>{$m}</div>";
}

function bcode_success($bcode_name)
{
echo "<div class='success'>A $bcode_name barcode was successfully created</div>";
}

function bcode_img64($b64str)
{
echo "<img src='data:image/png;base64,$b64str' /><br />";
}

?>
<html>
<head>

<title>Barcode Tester</title>

<style type="text/css">
.error, .success {
margin: 20px 0 20px 0;
font-weight: bold;
padding: 15px;
color: #FFF;
}

.error {
background-color: #A00;
}

.success {
background-color: #0A0;
}
</style>

</head>
<body>

<form action="example.php" method="post">

Enter Data to encode: <input type="text" name="encode" value="<?php echo (isset($_POST['encode']) ? htmlspecialchars($_POST['encode']) : 'Value 123456'); ?>" /><br />
<input type="submit" value="Encode" name="submit" />

</form>

<hr />

<?php

if (isset($_POST['submit'])) {

?>
Data to be encoded: <strong><?php echo htmlspecialchars($_POST['encode']); ?></strong><br />

<?php
foreach($bcode as $k => $value)
{
try
{
$bcode[$k]['obj']->setData($_POST['encode']);
$bcode[$k]['obj']->setDimensions(300, 150);
$bcode[$k]['obj']->draw();
$b64 = $bcode[$k]['obj']->base64();

bcode_success($bcode[$k]['name']);
bcode_img64($b64);
}
catch (Exception $e)
{
bcode_error($e->getMessage());
}
}
?>

<?php } ?>

</body>
</html>
File renamed without changes.
3 changes: 2 additions & 1 deletion Code128.php → src/Code128.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,13 @@ public function draw()
// Calc scaling
// Bars is in refrence to a single, 1-level bar
$numBarsRequired = ($this->type != self::TYPE_C) ? (sizeof($charAry) * 11) + 35 : ((sizeof($charAry)/2) * 11) + 35;
$this->x = ($this->x == 0) ? $numBarsRequired : $this->x;
$pxPerBar = (int) ($this->x / $numBarsRequired);
$currentX = ($this->x - ($numBarsRequired * $pxPerBar)) / 2;

if ($pxPerBar < 1)
{
throw new LogicException("Not enough space on this barcode for this message, increase the width of the barcode");
throw new \LogicException("Not enough space on this barcode for this message, increase the width of the barcode");
}

if ($this->type == self::TYPE_C)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.