/var/www/hkosl.com/oneMotorChunHing_delete20240201/html/bcclass/BCGDrawing.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?php
/**
 * BCGDrawing.php
 *--------------------------------------------------------------------
 *
 * Holds the drawing $im
 * You can use get_im() to add other kind of form not held into these classes.
 *
 *--------------------------------------------------------------------
 * Revision History
 * v2.1.0    8  nov    2009    Jean-Sébastien Goupil    Support DPI, Rotation
 * v2.0.1    8  mar    2009    Jean-Sébastien Goupil    Supports GIF and WBMP
 * v2.0.0    23 apr    2008    Jean-Sébastien Goupil    New Version Update
 * v1.2.3b    31 dec    2005    Jean-Sébastien Goupil    Just one barcode per drawing
 * v1.2.1    27 jun    2005    Jean-Sébastien Goupil    Font support added
 * V1.00    17 jun    2004    Jean-Sebastien Goupil
 *--------------------------------------------------------------------
 * $Id: BCGDrawing.php,v 1.12 2009/11/09 04:08:41 jsgoupil Exp $
 *--------------------------------------------------------------------
 * Copyright (C) Jean-Sebastien Goupil
 * http://www.barcodephp.com
 */
include_once('BCGBarcode.php');
include_once(
'drawer/BCGDrawJPG.php');
include_once(
'drawer/BCGDrawPNG.php');

class 
BCGDrawing {
    const 
IMG_FORMAT_PNG 1;
    const 
IMG_FORMAT_JPEG 2;
    const 
IMG_FORMAT_GIF 3;
    const 
IMG_FORMAT_WBMP 4;

    private 
$w$h;        // int
    
private $color;        // BCGColor
    
private $filename;    // char *
    
private $im;        // {object}
    
private $barcode;    // BCGBarcode
    
private $dpi;        // int
    
private $rotateDegree;    // float

    /**
     * Constructor
     *
     * @param int $w
     * @param int $h
     * @param string filename
     * @param BCGColor $color
     */
    
public function __construct($filenameBCGColor $color) {
        
$this->im null;
        
$this->setFilename($filename);
        
$this->color $color;
        
$this->dpi null;
        
$this->rotateDegree 0.0;
    }

    
/**
     * Destructor
     */
    
public function __destruct() {
        
$this->destroy();
    }

    
/**
     * Sets the filename
     *
     * @param string $filaneme
     */
    
public function setFilename($filename) {
        
$this->filename $filename;
    }

    
/**
     * Init Image and color background
     */
    
private function init() {
        if(
$this->im === null) {
            
$this->im imagecreatetruecolor($this->w$this->h)
            or die(
'Can\'t Initialize the GD Libraty');
            
imagefilledrectangle($this->im00$this->1$this->1$this->color->allocate($this->im));
        }
    }

    
/**
     * @return resource
     */
    
public function get_im() {
        return 
$this->im;
    }

    
/**
     * @param resource $im
     */
    
public function set_im(&$im) {
        
$this->im $im;
    }

    
/**
     * Set Barcode for drawing
     *
     * @param BCGBarcode $barcode
     */
    
public function setBarcode(BCGBarcode $barcode) {
        
$this->barcode $barcode;
    }

    
/**
     * Get the DPI for supported filetype
     *
     * @return int
     */
    
public function getDPI() {
        return 
$this->dpi;
    }

    
/**
     * Set the DPI for supported filetype
     *
     * @param float $dpi
     */
    
public function setDPI($dpi) {
        
$this->dpi $dpi;
    }

    
/**
     * Get the rotation angle in degree
     *
     * @return float
     */
    
public function getRotationAngle() {
        return 
$this->rotateDegree;
    }

    
/**
     * Set the rotation angle in degree
     *
     * @param float $degree
     */
    
public function setRotationAngle($degree) {
        
$this->rotateDegree = (float)$degree;
    }

    
/**
     * Draw the barcode on the image $im
     */
    
public function draw() {
        
$size $this->barcode->getMaxSize();
        
$this->max(1$size[0]);
        
$this->max(1$size[1]);
        
$this->init();
        
$this->barcode->draw($this->im);
    }

    
/**
     * Save $im into the file (many format available)
     *
     * @param int $image_style
     * @param int $quality
     */
    
public function finish($image_style self::IMG_FORMAT_PNG$quality 100) {
        
$drawer null;

        
$im $this->im;
        if(
$this->rotateDegree 0.0) {
            
$im imagerotate($this->im$this->rotateDegree$this->color->allocate($this->im));
        }

        if (
$image_style === self::IMG_FORMAT_PNG) {
            
$drawer = new BCGDrawPNG($im);
            
$drawer->setFilename($this->filename);
            
$drawer->setDPI($this->dpi);
        } elseif (
$image_style === self::IMG_FORMAT_JPEG) {
            
$drawer = new BCGDrawJPG($im);
            
$drawer->setFilename($this->filename);
            
$drawer->setDPI($this->dpi);
            
$drawer->setQuality($quality);
        } elseif (
$image_style === self::IMG_FORMAT_GIF) {
            
imagegif($im$this->filename);
        } elseif (
$image_style === self::IMG_FORMAT_WBMP) {
            
imagewbmp($im$this->filename);
        }

        if(
$drawer !== null) {
            
$drawer->draw();
        }
    }

    
/**
     * Free the memory of PHP (called also by destructor)
     */
    
public function destroy() {
        @
imagedestroy($this->im);
    }
};
?>