Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 159 lines (139 sloc) 4.84 kB
5e88c38 *** empty log message ***
Marcelo Subtil Marcal authored
1 <?php
2 /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
bc83954 - Added Code128 barcode rendering (thanks to Jeffrey K. Brown)
Marcelo Subtil Marcal authored
3
4 /**
a931a7d @CloCkWeRX php5
CloCkWeRX authored
5 * Image_Barcode2 class
bc83954 - Added Code128 barcode rendering (thanks to Jeffrey K. Brown)
Marcelo Subtil Marcal authored
6 *
7 * Package to render barcodes
8 *
d17ca3b @CloCkWeRX Request #17532I mprove coding style - php5
CloCkWeRX authored
9 * PHP versions 5
bc83954 - Added Code128 barcode rendering (thanks to Jeffrey K. Brown)
Marcelo Subtil Marcal authored
10 *
11 * LICENSE: This source file is subject to version 3.0 of the PHP license
12 * that is available through the world-wide-web at the following URI:
13 * http://www.php.net/license/3_0.txt. If you did not receive a copy of
14 * the PHP License and are unable to obtain it through the web, please
15 * send a note to license@php.net so we can mail you a copy immediately.
16 *
acec7ee @CloCkWeRX Issue #2 PHPCS
CloCkWeRX authored
17 * @category Image
18 * @package Image_Barcode2
19 * @author Marcelo Subtil Marcal <msmarcal@php.net>
20 * @copyright 2005 The PHP Group
21 * @license http://www.php.net/license/3_0.txt PHP License 3.0
22 * @version CVS: $Id$
23 * @link http://pear.php.net/package/Image_Barcode2
bc83954 - Added Code128 barcode rendering (thanks to Jeffrey K. Brown)
Marcelo Subtil Marcal authored
24 */
5e88c38 *** empty log message ***
Marcelo Subtil Marcal authored
25
d4e8d04 @cweiske Fix nasty include check and try to include directly.
cweiske authored
26 require_once 'PEAR.php';
0522043 @CloCkWeRX All drivers accept a writer for issue #2
CloCkWeRX authored
27 require_once 'Image/Barcode2/Writer.php';
7958cf3 @CloCkWeRX Issue #5 - Refactor class to know about drivers
CloCkWeRX authored
28 require_once 'Image/Barcode2/Driver.php';
5e88c38 *** empty log message ***
Marcelo Subtil Marcal authored
29
30 /**
a931a7d @CloCkWeRX php5
CloCkWeRX authored
31 * Image_Barcode2 class
bc83954 - Added Code128 barcode rendering (thanks to Jeffrey K. Brown)
Marcelo Subtil Marcal authored
32 *
33 * Package which provides a method to create barcode using GD library.
5e88c38 *** empty log message ***
Marcelo Subtil Marcal authored
34 *
acec7ee @CloCkWeRX Issue #2 PHPCS
CloCkWeRX authored
35 * @category Image
36 * @package Image_Barcode2
37 * @author Marcelo Subtil Marcal <msmarcal@php.net>
38 * @copyright 2005 The PHP Group
39 * @license http://www.php.net/license/3_0.txt PHP License 3.0
40 * @version Release: @package_version@
41 * @link http://pear.php.net/package/Image_Barcode2
5e88c38 *** empty log message ***
Marcelo Subtil Marcal authored
42 */
c840568 @Gemorroj Removed unnecessary extends
Gemorroj authored
43 class Image_Barcode2
5e88c38 *** empty log message ***
Marcelo Subtil Marcal authored
44 {
a500362 @Gemorroj add barcode types
Gemorroj authored
45 /**
46 * Image type
47 */
6c3560c @Gemorroj some fixes
Gemorroj authored
48 const IMAGE_PNG = 'png';
49 const IMAGE_GIF = 'gif';
50 const IMAGE_JPEG = 'jpg';
51
5e88c38 *** empty log message ***
Marcelo Subtil Marcal authored
52 /**
a500362 @Gemorroj add barcode types
Gemorroj authored
53 * Barcode type
54 */
55 const BARCODE_CODE39 = 'code39';
56 const BARCODE_INT25 = 'int25';
57 const BARCODE_EAN13 = 'ean13';
58 const BARCODE_UPCA = 'upca';
59 const BARCODE_CODE128 = 'code128';
60 const BARCODE_EAN8 = 'ean8';
61 const BARCODE_POSTNET = 'postnet';
62
63
64 /**
5e88c38 *** empty log message ***
Marcelo Subtil Marcal authored
65 * Draws a image barcode
66 *
acec7ee @CloCkWeRX Issue #2 PHPCS
CloCkWeRX authored
67 * @param string $text A text that should be in the image barcode
68 * @param string $type The barcode type. Supported types:
69 * Code39 - Code 3 of 9
70 * int25 - 2 Interleaved 5
71 * ean13 - EAN 13
72 * upca - UPC-A
73 * code128
74 * ean8
75 * postnet
76 * @param string $imgtype The image type that will be generated
77 * (gif, jpg, png)
78 * @param boolean $bSendToBrowser if the image shall be outputted to the
79 * browser, or be returned.
80 * @param integer $height The image height
81 * @param integer $width The image width
5e88c38 *** empty log message ***
Marcelo Subtil Marcal authored
82 *
acec7ee @CloCkWeRX Issue #2 PHPCS
CloCkWeRX authored
83 * @return image The corresponding gd image object;
84 * PEAR_Error on failure
5e88c38 *** empty log message ***
Marcelo Subtil Marcal authored
85 *
86 * @access public
bc83954 - Added Code128 barcode rendering (thanks to Jeffrey K. Brown)
Marcelo Subtil Marcal authored
87 *
5e88c38 *** empty log message ***
Marcelo Subtil Marcal authored
88 * @author Marcelo Subtil Marcal <msmarcal@php.net>
a931a7d @CloCkWeRX php5
CloCkWeRX authored
89 * @since Image_Barcode2 0.3
5e88c38 *** empty log message ***
Marcelo Subtil Marcal authored
90 */
8e71cee @Gemorroj Merge branch 'master' of https://github.com/pear/Image_Barcode2
Gemorroj authored
91 public static function draw($text,
acec7ee @CloCkWeRX Issue #2 PHPCS
CloCkWeRX authored
92 $type = Image_Barcode2::BARCODE_INT25,
93 $imgtype = Image_Barcode2::IMAGE_PNG,
94 $bSendToBrowser = true,
95 $height = 60,
96 $width = 1
97 ) {
d4e8d04 @cweiske Fix nasty include check and try to include directly.
cweiske authored
98 //Make sure no bad files are included
99 if (!preg_match('/^[a-zA-Z0-9_-]+$/', $type)) {
100 return PEAR::raiseError('Invalid barcode type ' . $type);
bc83954 - Added Code128 barcode rendering (thanks to Jeffrey K. Brown)
Marcelo Subtil Marcal authored
101 }
acec7ee @CloCkWeRX Issue #2 PHPCS
CloCkWeRX authored
102 if (!include_once 'Image/Barcode2/' . $type . '.php') {
d4e8d04 @cweiske Fix nasty include check and try to include directly.
cweiske authored
103 return PEAR::raiseError($type . ' barcode is not supported');
bc83954 - Added Code128 barcode rendering (thanks to Jeffrey K. Brown)
Marcelo Subtil Marcal authored
104 }
5e88c38 *** empty log message ***
Marcelo Subtil Marcal authored
105
a931a7d @CloCkWeRX php5
CloCkWeRX authored
106 $classname = 'Image_Barcode2_' . $type;
5e88c38 *** empty log message ***
Marcelo Subtil Marcal authored
107
7958cf3 @CloCkWeRX Issue #5 - Refactor class to know about drivers
CloCkWeRX authored
108 $writer = new Image_Barcode2_Writer();
109
110 $obj = new $classname($writer);
111
112 if (!$obj instanceof Image_Barcode2_Driver) {
acec7ee @CloCkWeRX Issue #2 PHPCS
CloCkWeRX authored
113 return PEAR::raiseError(
114 "Unable to find draw method in '$classname' class"
115 );
5e88c38 *** empty log message ***
Marcelo Subtil Marcal authored
116 }
117
ca20686 @CloCkWeRX #4 - Mark different kinds of classes with different interfaces even i…
CloCkWeRX authored
118 if (!$obj instanceof Image_Barcode2_DualWidth) {
119 $obj->setBarWidth($width);
acec7ee @CloCkWeRX Issue #2 PHPCS
CloCkWeRX authored
120 }
121
ca20686 @CloCkWeRX #4 - Mark different kinds of classes with different interfaces even i…
CloCkWeRX authored
122 if (!$obj instanceof Image_Barcode2_DualHeight) {
123 $obj->setBarcodeHeight($height);
acec7ee @CloCkWeRX Issue #2 PHPCS
CloCkWeRX authored
124 }
5e88c38 *** empty log message ***
Marcelo Subtil Marcal authored
125
ca20686 @CloCkWeRX #4 - Mark different kinds of classes with different interfaces even i…
CloCkWeRX authored
126
6c3560c @Gemorroj some fixes
Gemorroj authored
127 $img = $obj->draw($text);
5e88c38 *** empty log message ***
Marcelo Subtil Marcal authored
128
c840568 @Gemorroj Removed unnecessary extends
Gemorroj authored
129 if (@PEAR::isError($img)) {
09867bc @cweiske Fixing bug #8813: image can't be saved to filesystem
cweiske authored
130 return $img;
131 }
132
133 if ($bSendToBrowser) {
134 // Send image to browser
135 switch ($imgtype) {
acec7ee @CloCkWeRX Issue #2 PHPCS
CloCkWeRX authored
136 case self::IMAGE_GIF:
137 header('Content-type: image/gif');
138 imagegif($img);
139 imagedestroy($img);
140 break;
141
142 case self::IMAGE_JPEG:
143 header('Content-type: image/jpg');
144 imagejpeg($img);
145 imagedestroy($img);
146 break;
147
148 default:
149 header('Content-type: image/png');
150 imagepng($img);
151 imagedestroy($img);
152 break;
09867bc @cweiske Fixing bug #8813: image can't be saved to filesystem
cweiske authored
153 }
154 }
d17ca3b @CloCkWeRX Request #17532I mprove coding style - php5
CloCkWeRX authored
155
c840568 @Gemorroj Removed unnecessary extends
Gemorroj authored
156 return $img;
09867bc @cweiske Fixing bug #8813: image can't be saved to filesystem
cweiske authored
157 }
158 }
Something went wrong with that request. Please try again.