[2] | 1 | <?php
|
---|
| 2 | //=======================================================================
|
---|
[284] | 3 | // File: JPGRAPH_LED.PHP
|
---|
| 4 | // Description: Module to generate Dotted LED-like digits
|
---|
| 5 | // Created: 2006-11-26
|
---|
| 6 | // Ver: $Id: jpgraph_led.php 1674 2009-07-22 19:42:23Z ljp $
|
---|
[2] | 7 | //
|
---|
[284] | 8 | // Copyright 2006 (c) Asial Corporation. All rights reserved.
|
---|
[2] | 9 | //
|
---|
| 10 | // Changed: 2007-08-06 by Alexander Kurochkin (inspector@list.ru)
|
---|
| 11 | //========================================================================
|
---|
| 12 |
|
---|
[284] | 13 | // Constants for color schema
|
---|
| 14 | DEFINE('LEDC_RED', 0);
|
---|
| 15 | DEFINE('LEDC_GREEN', 1);
|
---|
| 16 | DEFINE('LEDC_BLUE', 2);
|
---|
| 17 | DEFINE('LEDC_YELLOW', 3);
|
---|
| 18 | DEFINE('LEDC_GRAY', 4);
|
---|
| 19 | DEFINE('LEDC_CHOCOLATE', 5);
|
---|
| 20 | DEFINE('LEDC_PERU', 6);
|
---|
| 21 | DEFINE('LEDC_GOLDENROD', 7);
|
---|
| 22 | DEFINE('LEDC_KHAKI', 8);
|
---|
| 23 | DEFINE('LEDC_OLIVE', 9);
|
---|
| 24 | DEFINE('LEDC_LIMEGREEN', 10);
|
---|
| 25 | DEFINE('LEDC_FORESTGREEN', 11);
|
---|
| 26 | DEFINE('LEDC_TEAL', 12);
|
---|
| 27 | DEFINE('LEDC_STEELBLUE', 13);
|
---|
| 28 | DEFINE('LEDC_NAVY', 14);
|
---|
| 29 | DEFINE('LEDC_INVERTGRAY', 15);
|
---|
[2] | 30 |
|
---|
[284] | 31 | // Check that mb_strlen() is available
|
---|
| 32 | if( ! function_exists('mb_strlen') ) {
|
---|
| 33 | JpGraphError::RaiseL(25500);
|
---|
| 34 | //'Multibyte strings must be enabled in the PHP installation in order to run the LED module
|
---|
| 35 | // so that the function mb_strlen() is available. See PHP documentation for more information.'
|
---|
| 36 | }
|
---|
[2] | 37 |
|
---|
| 38 | //========================================================================
|
---|
| 39 | // CLASS DigitalLED74
|
---|
[284] | 40 | // Description:
|
---|
[2] | 41 | // Construct a number as an image that looks like LED numbers in a
|
---|
| 42 | // 7x4 digital matrix
|
---|
| 43 | //========================================================================
|
---|
| 44 | class DigitalLED74
|
---|
| 45 | {
|
---|
| 46 | private $iLED_X = 4, $iLED_Y=7,
|
---|
| 47 |
|
---|
[284] | 48 | // fg-up, fg-down, bg
|
---|
| 49 | $iColorSchema = array(
|
---|
| 50 | LEDC_RED => array('red','darkred:0.9','red:0.3'),// 0
|
---|
| 51 | LEDC_GREEN => array('green','darkgreen','green:0.3'),// 1
|
---|
| 52 | LEDC_BLUE => array('lightblue:0.9','darkblue:0.85','darkblue:0.7'),// 2
|
---|
| 53 | LEDC_YELLOW => array('yellow','yellow:0.4','yellow:0.3'),// 3
|
---|
| 54 | LEDC_GRAY => array('gray:1.4','darkgray:0.85','darkgray:0.7'),
|
---|
| 55 | LEDC_CHOCOLATE => array('chocolate','chocolate:0.7','chocolate:0.5'),
|
---|
| 56 | LEDC_PERU => array('peru:0.95','peru:0.6','peru:0.5'),
|
---|
| 57 | LEDC_GOLDENROD => array('goldenrod','goldenrod:0.6','goldenrod:0.5'),
|
---|
| 58 | LEDC_KHAKI => array('khaki:0.7','khaki:0.4','khaki:0.3'),
|
---|
| 59 | LEDC_OLIVE => array('#808000','#808000:0.7','#808000:0.6'),
|
---|
| 60 | LEDC_LIMEGREEN => array('limegreen:0.9','limegreen:0.5','limegreen:0.4'),
|
---|
| 61 | LEDC_FORESTGREEN => array('forestgreen','forestgreen:0.7','forestgreen:0.5'),
|
---|
| 62 | LEDC_TEAL => array('teal','teal:0.7','teal:0.5'),
|
---|
| 63 | LEDC_STEELBLUE => array('steelblue','steelblue:0.65','steelblue:0.5'),
|
---|
| 64 | LEDC_NAVY => array('navy:1.3','navy:0.95','navy:0.8'),//14
|
---|
| 65 | LEDC_INVERTGRAY => array('darkgray','lightgray:1.5','white')//15
|
---|
| 66 | ),
|
---|
[2] | 67 |
|
---|
[284] | 68 | /* Each line of the character is encoded as a 4 bit value
|
---|
| 69 | 0 ____
|
---|
| 70 | 1 ___x
|
---|
| 71 | 2 __x_
|
---|
| 72 | 3 __xx
|
---|
| 73 | 4 _x__
|
---|
| 74 | 5 _x_x
|
---|
| 75 | 6 _xx_
|
---|
| 76 | 7 _xxx
|
---|
| 77 | 8 x___
|
---|
| 78 | 9 x__x
|
---|
| 79 | 10 x_x_
|
---|
| 80 | 11 x_xx
|
---|
| 81 | 12 xx__
|
---|
| 82 | 13 xx_x
|
---|
| 83 | 14 xxx_
|
---|
| 84 | 15 xxxx
|
---|
| 85 | */
|
---|
[2] | 86 |
|
---|
[284] | 87 | $iLEDSpec = array(
|
---|
| 88 | 0 => array(6,9,11,15,13,9,6),
|
---|
| 89 | 1 => array(2,6,10,2,2,2,2),
|
---|
| 90 | 2 => array(6,9,1,2,4,8,15),
|
---|
| 91 | 3 => array(6,9,1,6,1,9,6),
|
---|
| 92 | 4 => array(1,3,5,9,15,1,1),
|
---|
| 93 | 5 => array(15,8,8,14,1,9,6),
|
---|
| 94 | 6 => array(6,8,8,14,9,9,6),
|
---|
| 95 | 7 => array(15,1,1,2,4,4,4),
|
---|
| 96 | 8 => array(6,9,9,6,9,9,6),
|
---|
| 97 | 9 => array(6,9,9,7,1,1,6),
|
---|
| 98 | '!' => array(4,4,4,4,4,0,4),
|
---|
| 99 | '?' => array(6,9,1,2,2,0,2),
|
---|
| 100 | '#' => array(0,9,15,9,15,9,0),
|
---|
| 101 | '@' => array(6,9,11,11,10,9,6),
|
---|
| 102 | '-' => array(0,0,0,15,0,0,0),
|
---|
| 103 | '_' => array(0,0,0,0,0,0,15),
|
---|
| 104 | '=' => array(0,0,15,0,15,0,0),
|
---|
| 105 | '+' => array(0,0,4,14,4,0,0),
|
---|
| 106 | '|' => array(4,4,4,4,4,4,4), //vertical line, used for simulate rus 'Ы'
|
---|
| 107 | ',' => array(0,0,0,0,0,12,4),
|
---|
| 108 | '.' => array(0,0,0,0,0,12,12),
|
---|
| 109 | ':' => array(12,12,0,0,0,12,12),
|
---|
| 110 | ';' => array(12,12,0,0,0,12,4),
|
---|
| 111 | '[' => array(3,2,2,2,2,2,3),
|
---|
| 112 | ']' => array(12,4,4,4,4,4,12),
|
---|
| 113 | '(' => array(1,2,2,2,2,2,1),
|
---|
| 114 | ')' => array(8,4,4,4,4,4,8),
|
---|
| 115 | '{' => array(3,2,2,6,2,2,3),
|
---|
| 116 | '}' => array(12,4,4,6,4,4,12),
|
---|
| 117 | '<' => array(1,2,4,8,4,2,1),
|
---|
| 118 | '>' => array(8,4,2,1,2,4,8),
|
---|
| 119 | '*' => array(9,6,15,6,9,0,0),
|
---|
| 120 | '"' => array(10,10,0,0,0,0,0),
|
---|
| 121 | '\'' => array(4,4,0,0,0,0,0),
|
---|
| 122 | '`' => array(4,2,0,0,0,0,0),
|
---|
| 123 | '~' => array(13,11,0,0,0,0,0),
|
---|
| 124 | '^' => array(4,10,0,0,0,0,0),
|
---|
| 125 | '\\' => array(8,8,4,6,2,1,1),
|
---|
| 126 | '/' => array(1,1,2,6,4,8,8),
|
---|
| 127 | '%' => array(1,9,2,6,4,9,8),
|
---|
| 128 | '&' => array(0,4,10,4,11,10,5),
|
---|
| 129 | '$' => array(2,7,8,6,1,14,4),
|
---|
| 130 | ' ' => array(0,0,0,0,0,0,0),
|
---|
| 131 | 'â¢' => array(0,0,6,6,0,0,0), //149
|
---|
| 132 | '°' => array(14,10,14,0,0,0,0), //176
|
---|
| 133 | 'â ' => array(4,4,14,4,4,4,4), //134
|
---|
| 134 | 'â¡' => array(4,4,14,4,14,4,4), //135
|
---|
| 135 | '±' => array(0,4,14,4,0,14,0), //177
|
---|
| 136 | 'â°' => array(0,4,2,15,2,4,0), //137 show right arrow
|
---|
| 137 | 'â¢' => array(0,2,4,15,4,2,0), //156 show left arrow
|
---|
| 138 | 'Ð' => array(0,0,8,8,0,0,0), //159 show small hi-stick - that need for simulate rus 'Ѐ'
|
---|
| 139 | "\t" => array(8,8,8,0,0,0,0), //show hi-stick - that need for simulate rus 'У'
|
---|
| 140 | "\r" => array(8,8,8,8,8,8,8), //vertical line - that need for simulate 'M', 'W' and rus 'Ð','К' ,'Щ'
|
---|
| 141 | "\n" => array(15,15,15,15,15,15,15), //fill up - that need for simulate rus 'Ð'
|
---|
| 142 | "Ò" => array(10,5,10,5,10,5,10), //chess
|
---|
| 143 | "µ" => array(15,0,15,0,15,0,15), //4 horizontal lines
|
---|
| 144 | // latin
|
---|
| 145 | 'A' => array(6,9,9,15,9,9,9),
|
---|
| 146 | 'B' => array(14,9,9,14,9,9,14),
|
---|
| 147 | 'C' => array(6,9,8,8,8,9,6),
|
---|
| 148 | 'D' => array(14,9,9,9,9,9,14),
|
---|
| 149 | 'E' => array(15,8,8,14,8,8,15),
|
---|
| 150 | 'F' => array(15,8,8,14,8,8,8),
|
---|
| 151 | 'G' => array(6,9,8,8,11,9,6),
|
---|
| 152 | 'H' => array(9,9,9,15,9,9,9),
|
---|
| 153 | 'I' => array(14,4,4,4,4,4,14),
|
---|
| 154 | 'J' => array(15,1,1,1,1,9,6),
|
---|
| 155 | 'K' => array(8,9,10,12,12,10,9),
|
---|
| 156 | 'L' => array(8,8,8,8,8,8,15),
|
---|
| 157 | 'M' => array(8,13,10,8,8,8,8),// need to add \r
|
---|
| 158 | 'N' => array(9,9,13,11,9,9,9),
|
---|
| 159 | 'O' => array(6,9,9,9,9,9,6),
|
---|
| 160 | 'P' => array(14,9,9,14,8,8,8),
|
---|
| 161 | 'Q' => array(6,9,9,9,13,11,6),
|
---|
| 162 | 'R' => array(14,9,9,14,12,10,9),
|
---|
| 163 | 'S' => array(6,9,8,6,1,9,6),
|
---|
| 164 | 'T' => array(14,4,4,4,4,4,4),
|
---|
| 165 | 'U' => array(9,9,9,9,9,9,6),
|
---|
| 166 | 'V' => array(0,0,0,10,10,10,4),
|
---|
| 167 | 'W' => array(8,8,8,8,10,13,8),// need to add \r
|
---|
| 168 | 'X' => array(9,9,6,6,6,9,9),
|
---|
| 169 | 'Y' => array(10,10,10,10,4,4,4),
|
---|
| 170 | 'Z' => array(15,1,2,6,4,8,15),
|
---|
| 171 | // russian utf-8
|
---|
| 172 | 'Ð' => array(6,9,9,15,9,9,9),
|
---|
| 173 | 'Ð' => array(14,8,8,14,9,9,14),
|
---|
| 174 | 'Ð' => array(14,9,9,14,9,9,14),
|
---|
| 175 | 'Ð' => array(15,8,8,8,8,8,8),
|
---|
| 176 | 'Ð' => array(14,9,9,9,9,9,14),
|
---|
| 177 | 'Ð' => array(15,8,8,14,8,8,15),
|
---|
| 178 | 'Ð' => array(6,15,8,14,8,8,15),
|
---|
| 179 | //Ð is combine: >\n<
|
---|
| 180 | 'Ð' => array(6,9,1,2,1,9,6),
|
---|
| 181 | 'Ð' => array(9,9,9,11,13,9,9),
|
---|
| 182 | 'Ð' => array(13,9,9,11,13,9,9),
|
---|
| 183 | 'Ð' => array(9,10,12,10,9,9,9),
|
---|
| 184 | 'Ð' => array(7,9,9,9,9,9,9),
|
---|
| 185 | 'Ð' => array(8,13,10,8,8,8,8),// need to add \r
|
---|
| 186 | 'Ð' => array(9,9,9,15,9,9,9),
|
---|
| 187 | 'Ð' => array(6,9,9,9,9,9,6),
|
---|
| 188 | 'Ð' => array(15,9,9,9,9,9,9),
|
---|
| 189 | 'Ð ' => array(14,9,9,14,8,8,8),
|
---|
| 190 | 'С' => array(6,9,8,8,8,9,6),
|
---|
| 191 | 'Т' => array(14,4,4,4,4,4,4),
|
---|
| 192 | 'У' => array(9,9,9,7,1,9,6),
|
---|
| 193 | 'Ѐ' => array(2,7,10,10,7,2,2),// need to add Ð
|
---|
| 194 | 'Ð¥' => array(9,9,6,6,6,9,9),
|
---|
| 195 | 'Њ' => array(10,10,10,10,10,15,1),
|
---|
| 196 | 'Ч' => array(9,9,9,7,1,1,1),
|
---|
| 197 | 'К' => array(10,10,10,10,10,10,15),// \r
|
---|
| 198 | 'Щ' => array(10,10,10,10,10,15,0),// need to add \r
|
---|
| 199 | 'Ъ' => array(12,4,4,6,5,5,6),
|
---|
| 200 | 'Ы' => array(8,8,8,14,9,9,14),// need to add |
|
---|
| 201 | 'Ь' => array(8,8,8,14,9,9,14),
|
---|
| 202 | 'Ð' => array(6,9,1,7,1,9,6),
|
---|
| 203 | 'Ю' => array(2,2,2,3,2,2,2),// need to add O
|
---|
| 204 | 'Я' => array(7,9,9,7,3,5,9)
|
---|
| 205 | ),
|
---|
| 206 |
|
---|
| 207 | $iSuperSampling = 3, $iMarg = 1, $iRad = 4;
|
---|
| 208 |
|
---|
| 209 | function __construct($aRadius = 2, $aMargin= 0.6) {
|
---|
| 210 | $this->iRad = $aRadius;
|
---|
| 211 | $this->iMarg = $aMargin;
|
---|
[2] | 212 | }
|
---|
[284] | 213 |
|
---|
| 214 | function SetSupersampling($aSuperSampling = 2) {
|
---|
| 215 | $this->iSuperSampling = $aSuperSampling;
|
---|
[2] | 216 | }
|
---|
| 217 |
|
---|
[284] | 218 | function _GetLED($aLedIdx, $aColor = 0) {
|
---|
| 219 | $width= $this->iLED_X*$this->iRad*2 + ($this->iLED_X+1)*$this->iMarg + $this->iRad ;
|
---|
| 220 | $height= $this->iLED_Y*$this->iRad*2 + ($this->iLED_Y)*$this->iMarg + $this->iRad * 2;
|
---|
[2] | 221 |
|
---|
[284] | 222 | // Adjust radious for supersampling
|
---|
| 223 | $rad = $this->iRad * $this->iSuperSampling;
|
---|
[2] | 224 |
|
---|
[284] | 225 | // Margin in between "Led" dots
|
---|
| 226 | $marg = $this->iMarg * $this->iSuperSampling;
|
---|
[2] | 227 |
|
---|
[284] | 228 | $swidth = $width*$this->iSuperSampling;
|
---|
| 229 | $sheight = $height*$this->iSuperSampling;
|
---|
[2] | 230 |
|
---|
[284] | 231 | $simg = new RotImage($swidth, $sheight, 0, DEFAULT_GFORMAT, false);
|
---|
| 232 | $simg->SetColor($this->iColorSchema[$aColor][2]);
|
---|
| 233 | $simg->FilledRectangle(0, 0, $swidth-1, $sheight-1);
|
---|
[2] | 234 |
|
---|
[284] | 235 | if( array_key_exists($aLedIdx, $this->iLEDSpec) ) {
|
---|
| 236 | $d = $this->iLEDSpec[$aLedIdx];
|
---|
| 237 | }
|
---|
| 238 | else {
|
---|
| 239 | $d = array(0,0,0,0,0,0,0);
|
---|
| 240 | }
|
---|
[2] | 241 |
|
---|
[284] | 242 | for($r = 0; $r < 7; ++$r) {
|
---|
| 243 | $dr = $d[$r];
|
---|
| 244 | for($c = 0; $c < 4; ++$c) {
|
---|
| 245 | if( ($dr & pow(2,3-$c)) !== 0 ) {
|
---|
| 246 | $color = $this->iColorSchema[$aColor][0];
|
---|
| 247 | }
|
---|
| 248 | else {
|
---|
| 249 | $color = $this->iColorSchema[$aColor][1];
|
---|
| 250 | }
|
---|
[2] | 251 |
|
---|
[284] | 252 | $x = 2*$rad*$c+$rad + ($c+1)*$marg + $rad ;
|
---|
| 253 | $y = 2*$rad*$r+$rad + ($r+1)*$marg + $rad ;
|
---|
[2] | 254 |
|
---|
[284] | 255 | $simg->SetColor($color);
|
---|
| 256 | $simg->FilledCircle($x,$y,$rad);
|
---|
| 257 | }
|
---|
| 258 | }
|
---|
| 259 |
|
---|
| 260 | $img = new Image($width, $height, DEFAULT_GFORMAT, false);
|
---|
| 261 | $img->Copy($simg->img, 0, 0, 0, 0, $width, $height, $swidth, $sheight);
|
---|
| 262 | $simg->Destroy();
|
---|
| 263 | unset($simg);
|
---|
| 264 | return $img;
|
---|
[2] | 265 | }
|
---|
| 266 |
|
---|
[284] | 267 |
|
---|
| 268 | function Stroke($aValStr, $aColor = 0, $aFileName = '') {
|
---|
| 269 | $this->StrokeNumber($aValStr, $aColor, $aFileName);
|
---|
| 270 | }
|
---|
| 271 |
|
---|
| 272 |
|
---|
[2] | 273 | function StrokeNumber($aValStr, $aColor = 0, $aFileName = '') {
|
---|
[284] | 274 | if( $aColor < 0 || $aColor >= sizeof($this->iColorSchema) ) {
|
---|
| 275 | $aColor = 0;
|
---|
| 276 | }
|
---|
[2] | 277 |
|
---|
[284] | 278 | if(($n = mb_strlen($aValStr,'utf8')) == 0) {
|
---|
| 279 | $aValStr = ' ';
|
---|
| 280 | $n = 1;
|
---|
| 281 | }
|
---|
[2] | 282 |
|
---|
[284] | 283 | for($i = 0; $i < $n; ++$i) {
|
---|
| 284 | $d = mb_substr($aValStr, $i, 1, 'utf8');
|
---|
| 285 | if( ctype_digit($d) ) {
|
---|
| 286 | $d = (int)$d;
|
---|
| 287 | }
|
---|
| 288 | else {
|
---|
| 289 | $d = strtoupper($d);
|
---|
| 290 | }
|
---|
| 291 | $digit_img[$i] = $this->_GetLED($d, $aColor);
|
---|
| 292 | }
|
---|
[2] | 293 |
|
---|
[284] | 294 | $w = imagesx($digit_img[0]->img);
|
---|
| 295 | $h = imagesy($digit_img[0]->img);
|
---|
[2] | 296 |
|
---|
[284] | 297 | $number_img = new Image($w*$n, $h, DEFAULT_GFORMAT, false);
|
---|
[2] | 298 |
|
---|
[284] | 299 | for($i = 0; $i < $n; ++$i) {
|
---|
| 300 | $number_img->Copy($digit_img[$i]->img, $i*$w, 0, 0, 0, $w, $h, $w, $h);
|
---|
| 301 | }
|
---|
[2] | 302 |
|
---|
[284] | 303 | if( $aFileName != '' ) {
|
---|
| 304 | $number_img->Stream($aFileName);
|
---|
| 305 | } else {
|
---|
| 306 | $number_img->Headers();
|
---|
| 307 | $number_img->Stream();
|
---|
| 308 | }
|
---|
[2] | 309 | }
|
---|
| 310 | }
|
---|
| 311 | ?>
|
---|