Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add showtext and rotation option

  • Loading branch information...
commit 45ce63b3ad6cb7dff500c4800cd855f71e356f33 1 parent bd7e48e
Marcel Pennewiss authored
View
20 Image/Barcode2.php
@@ -60,6 +60,14 @@ class Image_Barcode2
const BARCODE_EAN8 = 'ean8';
const BARCODE_POSTNET = 'postnet';
+ /**
+ * Rotation type
+ */
+ const ROTATE_NONE = '0';
+ const ROTATE_RIGHT = '90';
+ const ROTATE_UTURN = '180';
+ const ROTATE_LEFT = '270';
+
/**
* Draws a image barcode
@@ -80,6 +88,8 @@ class Image_Barcode2
* browser, or be returned.
* @param integer $height The image height
* @param integer $width The image width
+ * @param boolean $showText The text should be placed under barcode
+ * @param integer $rotation The rotation angle
*
* @return resource The corresponding gd image resource
*
@@ -94,7 +104,9 @@ public static function draw($text,
$imgtype = Image_Barcode2::IMAGE_PNG,
$bSendToBrowser = true,
$height = 60,
- $width = 1
+ $width = 1,
+ $showText = true,
+ $rotation = Image_Barcode2::ROTATE_NONE
) {
//Make sure no bad files are included
if (!preg_match('/^[a-zA-Z0-9]+$/', $type)) {
@@ -124,10 +136,16 @@ public static function draw($text,
}
$obj->setBarcode($text);
+ $obj->setShowText($showText);
$obj->validate();
$img = $obj->draw();
+ // Rotate image on demand
+ if ($rotation !== self::ROTATE_NONE) {
+ $img = imagerotate($img, $rotation, 0);
+ }
+
if ($bSendToBrowser) {
// Send image to browser
switch ($imgtype) {
View
23 Image/Barcode2/Common.php
@@ -41,6 +41,7 @@ class Image_Barcode2_Common
protected $barcodethinwidth;
protected $barcodethickwidth;
protected $fontsize = 2;
+ protected $showText;
/**
* @var Image_Barcode2_Writer
@@ -107,6 +108,28 @@ public function getBarcode()
return $this->barcode;
}
+ /**
+ * Set if text will be placed under the barcode
+ *
+ * @param boolean $showText The text should be placed under barcode
+ *
+ * @return void
+ */
+ public function setShowText($showText)
+ {
+ $this->showText = $showText;
+ }
+
+ /**
+ * Get if text will be placed under the barcode
+ *
+ * @return boolean
+ */
+ public function getShowText()
+ {
+ return $this->showText;
+ }
+
public function setFontSize($size)
{
$this->fontsize = $size;
View
18 Image/Barcode2/Driver/Code128.php
@@ -294,14 +294,16 @@ public function draw()
// First, print the image, centered across the bottom.
- $writer->imagestring(
- $img,
- $fontsize,
- $barcodewidth / 2 - strlen($text) / 2 * ($writer->imagefontwidth($fontsize)),
- $this->getBarcodeHeight() + $writer->imagefontheight($fontsize) / 2,
- $text,
- $black
- );
+ if ($this->showText) {
+ $writer->imagestring(
+ $img,
+ $fontsize,
+ $barcodewidth / 2 - strlen($text) / 2 * ($writer->imagefontwidth($fontsize)),
+ $this->getBarcodeHeight() + $writer->imagefontheight($fontsize) / 2,
+ $text,
+ $black
+ );
+ }
// We set $xpos to 10 so we start bar printing after
// position 10 to simulate the 10 pixel "Quiet Zone"
View
18 Image/Barcode2/Driver/Code39.php
@@ -188,14 +188,16 @@ public function draw()
}
// draw text under barcode
- $writer->imagestring(
- $img,
- $fontsize,
- ($barcode_len - $font_width * strlen($text)) / 2,
- $this->getBarcodeHeight() - $font_height,
- $text,
- $black
- );
+ if ($this->showText) {
+ $writer->imagestring(
+ $img,
+ $fontsize,
+ ($barcode_len - $font_width * strlen($text)) / 2,
+ $this->getBarcodeHeight() - $font_height,
+ $text,
+ $black
+ );
+ }
return $img;
View
57 Image/Barcode2/Driver/Ean13.php
@@ -190,16 +190,19 @@ public function draw()
$xpos = 0;
// print first digit
- $writer->imagestring(
- $img,
- $fontsize,
- $xpos,
- $this->getBarcodeHeight(),
- $key,
- $black
- );
+ if ($this->showText) {
+ $writer->imagestring(
+ $img,
+ $fontsize,
+ $xpos,
+ $this->getBarcodeHeight(),
+ $key,
+ $black
+ );
+
+ $xpos = $writer->imagefontwidth($fontsize) + 1;
+ };
- $xpos = $writer->imagefontwidth($fontsize) + 1;
// Draws the left guard pattern (bar-space-bar)
// bar
@@ -230,14 +233,16 @@ public function draw()
for ($idx = 1; $idx < 7; $idx ++) {
$value = substr($text, $idx, 1);
- $writer->imagestring(
- $img,
- $fontsize,
- $xpos + 1,
- $this->getBarcodeHeight(),
- $value,
- $black
- );
+ if ($this->showText) {
+ $writer->imagestring(
+ $img,
+ $fontsize,
+ $xpos + 1,
+ $this->getBarcodeHeight(),
+ $value,
+ $black
+ );
+ }
foreach ($this->_codingmap[$value][$set_array[$idx - 1]] as $bar) {
if ($bar) {
@@ -287,14 +292,16 @@ public function draw()
for ($idx = 7; $idx < 13; $idx ++) {
$value = substr($text, $idx, 1);
- $writer->imagestring(
- $img,
- $fontsize,
- $xpos + 1,
- $this->getBarcodeHeight(),
- $value,
- $black
- );
+ if ($this->showText) {
+ $writer->imagestring(
+ $img,
+ $fontsize,
+ $xpos + 1,
+ $this->getBarcodeHeight(),
+ $value,
+ $black
+ );
+ }
foreach ($this->_codingmap[$value]['C'] as $bar) {
if ($bar) {
View
38 Image/Barcode2/Driver/Ean8.php
@@ -186,14 +186,18 @@ public function draw()
for ($idx = 0; $idx < 4; $idx ++) {
$value = substr($text, $idx, 1);
- $writer->imagestring(
- $img,
- $fontsize,
- $xpos + 1,
- $this->getBarcodeHeight(),
- $value,
- $black
- );
+
+ if ($this->showText) {
+ $writer->imagestring(
+ $img,
+ $fontsize,
+ $xpos + 1,
+ $this->getBarcodeHeight(),
+ $value,
+ $black
+ );
+ }
+
foreach ($this->_codingmap[$value]['A'] as $bar) {
if ($bar) {
$writer->imagefilledrectangle(
@@ -244,14 +248,16 @@ public function draw()
for ($idx = 4; $idx < 8; $idx ++) {
$value = substr($text, $idx, 1);
- $writer->imagestring(
- $img,
- $fontsize,
- $xpos + 1,
- $this->getBarcodeHeight(),
- $value,
- $black
- );
+ if ($this->showText) {
+ $writer->imagestring(
+ $img,
+ $fontsize,
+ $xpos + 1,
+ $this->getBarcodeHeight(),
+ $value,
+ $black
+ );
+ }
foreach ($this->_codingmap[$value]['C'] as $bar) {
if ($bar) {
View
75 Image/Barcode2/Driver/Upca.php
@@ -172,14 +172,16 @@ public function draw()
$xpos = 0;
// print first digit
- $writer->imagestring(
- $img,
- $fontsize,
- $xpos,
- $this->getBarcodeHeight(),
- $key,
- $black
- );
+ if ($this->showText) {
+ $writer->imagestring(
+ $img,
+ $fontsize,
+ $xpos,
+ $this->getBarcodeHeight(),
+ $key,
+ $black
+ );
+ }
$xpos = $writer->imagefontwidth($fontsize) + 1;
@@ -229,14 +231,17 @@ public function draw()
// Draw left $text contents
for ($idx = 1; $idx < 6; $idx ++) {
$value = substr($text, $idx, 1);
- $writer->imagestring(
- $img,
- $fontsize,
- $xpos + 1,
- $this->getBarcodeHeight(),
- $value,
- $black
- );
+
+ if ($this->showText) {
+ $writer->imagestring(
+ $img,
+ $fontsize,
+ $xpos + 1,
+ $this->getBarcodeHeight(),
+ $value,
+ $black
+ );
+ }
foreach ($this->_codingmap[$value]['L'] as $bar) {
if ($bar) {
@@ -286,14 +291,18 @@ public function draw()
// Draw right $text contents
for ($idx = 6; $idx < 11; $idx ++) {
$value = substr($text, $idx, 1);
- $writer->imagestring(
- $img,
- $fontsize,
- $xpos + 1,
- $this->getBarcodeHeight(),
- $value,
- $black
- );
+
+ if ($this->showText) {
+ $writer->imagestring(
+ $img,
+ $fontsize,
+ $xpos + 1,
+ $this->getBarcodeHeight(),
+ $value,
+ $black
+ );
+ }
+
foreach ($this->_codingmap[$value]['R'] as $bar) {
if ($bar) {
$writer->imagefilledrectangle(
@@ -357,14 +366,16 @@ public function draw()
// Print Check Digit
- $writer->imagestring(
- $img,
- $fontsize,
- $xpos + 1,
- $this->getBarcodeHeight(),
- $value,
- $black
- );
+ if ($this->showText) {
+ $writer->imagestring(
+ $img,
+ $fontsize,
+ $xpos + 1,
+ $this->getBarcodeHeight(),
+ $value,
+ $black
+ );
+ }
return $img;
}
View
57 Image/Barcode2/Driver/Upce.php
@@ -178,14 +178,16 @@ public function draw()
$xpos = 0;
// print first digit
- $writer->imagestring(
- $img,
- $fontsize,
- $xpos,
- $this->getBarcodeHeight(),
- $key,
- $black
- );
+ if ($this->showText) {
+ $writer->imagestring(
+ $img,
+ $fontsize,
+ $xpos,
+ $this->getBarcodeHeight(),
+ $key,
+ $black
+ );
+ }
$xpos = $writer->imagefontwidth($fontsize) + 1;
@@ -220,15 +222,18 @@ public function draw()
$checkdigit = substr($text, 7, 1);
for ($idx = 1; $idx < 7; $idx ++) {
$value = substr($text, $idx, 1);
- $writer->imagestring(
- $img,
- $fontsize,
- $xpos + 1,
- $this->getBarcodeHeight(),
- $value,
- $black
- );
-
+
+ if ($this->showText) {
+ $writer->imagestring(
+ $img,
+ $fontsize,
+ $xpos + 1,
+ $this->getBarcodeHeight(),
+ $value,
+ $black
+ );
+ }
+
if ($this->_paritypattern[$checkdigit][$idx-1] == 1) {
foreach ($this->_codingmap[$value]['E'] as $bar) {
if ($bar) {
@@ -304,14 +309,16 @@ public function draw()
// Print Check Digit
- $writer->imagestring(
- $img,
- $fontsize,
- $xpos + 1,
- $this->getBarcodeHeight(),
- $checkdigit,
- $black
- );
+ if ($this->showText) {
+ $writer->imagestring(
+ $img,
+ $fontsize,
+ $xpos + 1,
+ $this->getBarcodeHeight(),
+ $checkdigit,
+ $black
+ );
+ }
return $img;
}
Please sign in to comment.
Something went wrong with that request. Please try again.