Skip to content

Commit

Permalink
fixing some formats + adding some docs to the Reame
Browse files Browse the repository at this point in the history
  • Loading branch information
elminson committed Sep 16, 2018
1 parent b450074 commit de1e459
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 59 deletions.
71 changes: 34 additions & 37 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 12 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
#BarCode

This script that generates barcodes in four barcode formats including
Code 128, Code 39, Code 2of5, and Codabar. With a little over 100 lines
of code you have the options of “vertical” or “horizontal” display,
varying barcode heights, and one of four barcode formats. It does require
the GD Library to be installed as a module in PHP.

####Basic use:
```php
namespace Elminson\BarCode;

require_once(__DIR__ . '/vendor/autoload.php');

$barcode = new BarCode('code128');
$barcode->setPrint(true);
$barcode->setTextColor("#ff9900");
$barcode->setBgColor("#cccccc");
$barcode->setFileName = "test";
$barcode->setFileName("test");
$barcode->setFilepath(__DIR__."/temp/");
echo $barcode->generate("testing");
```

Expand All @@ -19,16 +30,3 @@ php-barcode
Source code for the article "How To Create Barcodes in PHP" found at:
http://davidscotttufts.com/2009/03/31/how-to-create-barcodes-in-php/
This script that generates barcodes in four barcode formats including
Code 128, Code 39, Code 2of5, and Codabar. With a little over 100 lines
of code you have the options of “vertical” or “horizontal” display,
varying barcode heights, and one of four barcode formats. It does require
the GD Library to be installed as a module in PHP.
Usage:
<img alt="testing" src="barcode.php?text=testing" />
Result:
<img alt="testing" src="http://davidscotttufts.com/code/barcode.php?text=testing" />
```
3 changes: 1 addition & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
$barcode->setTextColor("#ff9900");
$barcode->setBgColor("#cccccc");
$barcode->setFileName("test");
$barcode->setFilepath("temp/");
$barcode->setFilepath(__DIR__."/temp/");
echo $barcode->generate("testing");
echo "\n";
//$barcode = new BarCode('code128b');
//echo $barcode->generate("testing");
//echo "\n";
Expand Down
15 changes: 9 additions & 6 deletions src/BarCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function getFile()
{
return $this->file;
}

public function setFileName($filename)
{
$this->file_name = $filename;
Expand Down Expand Up @@ -142,13 +143,15 @@ public function generate($text)
$this->setText($text);
if ($this->getCode_type() == "code25") {
$this->code_string = $this->barcode25();
} else if ($this->getCode_type() == "code39") {
$this->code_string = $this->barcode39();
} else {
if ($this->getCode_type() == "codabar") {
$this->code_string = $this->barcodabar();
if ($this->getCode_type() == "code39") {
$this->code_string = $this->barcode39();
} else {
$this->code_string = $this->barcodebase();
if ($this->getCode_type() == "codabar") {
$this->code_string = $this->barcodabar();
} else {
$this->code_string = $this->barcodebase();
}
}
}
$this->generateBarCodeImage();
Expand Down Expand Up @@ -353,7 +356,7 @@ public function generateBarCodeImage()
$name = $this->file_name;
}

echo $this->file = $this->filepath . $name . ".png";
$this->file = $this->filepath . $name . ".png";
imagepng($image, $this->file);
imagedestroy($image);
}
Expand Down

0 comments on commit de1e459

Please sign in to comment.