[30] | 1 | <?php |
---|
| 2 | class GifSplit |
---|
| 3 | { |
---|
| 4 | /*===========================================*/ |
---|
| 5 | /*== V A R I A B L E S ==*/ |
---|
| 6 | /*===========================================*/ |
---|
| 7 | var $gs_image_count = 0; |
---|
| 8 | var $gs_buffer = array(); |
---|
| 9 | var $gs_global_data = array(); |
---|
| 10 | var $gs_fileframe = array(); |
---|
| 11 | var $gs_gif = array(0x47, 0x49, 0x46); |
---|
| 12 | var $gs_header = "\x47\x49\x46\x38\x39\x61"; //GIF89a |
---|
| 13 | var $gs_logical_screen_size; |
---|
| 14 | var $gs_logical_screen_descriptor; |
---|
| 15 | var $gs_global_color_table_size; |
---|
| 16 | var $gs_global_color_table_code; |
---|
| 17 | var $gs_global_color_table_flag; |
---|
| 18 | var $gs_global_image_data; |
---|
| 19 | var $gs_extension_lenght; |
---|
| 20 | var $gs_extension_type; |
---|
| 21 | var $gs_image_descriptor; |
---|
| 22 | var $gs_global_sorted; |
---|
| 23 | var $gs_fin; |
---|
| 24 | var $gs_fou; |
---|
| 25 | var $gs_sp; |
---|
| 26 | var $gs_fm; |
---|
| 27 | var $gs_es; |
---|
| 28 | var $gs_imnbr; |
---|
| 29 | var $gs_rsz; |
---|
| 30 | |
---|
| 31 | function GifSplit($image, $format, $name, $max_im_index='0', $resize='1') |
---|
| 32 | { |
---|
| 33 | error_reporting(0); |
---|
| 34 | $this->gs_fm = $format; |
---|
| 35 | $this->gs_sp = $name; |
---|
| 36 | $this->gs_imnbr = ($max_im_index=='')? '-1' : $max_im_index ; // maximal image index (from 0 to n) |
---|
| 37 | $this->gs_rsz = ($resize=='')? '0' : $resize ; //0: no change, 1: resize logical screen size to image size |
---|
| 38 | if ($this->gs_fm != 'GIF') $this->gs_rsz =1; |
---|
| 39 | |
---|
| 40 | if($this->gs_fin = fopen($image, "rb")) |
---|
| 41 | { |
---|
| 42 | $this->getbytes(6); |
---|
| 43 | if(!$this->arrcmp($this->gs_buffer, $this->gs_gif, 3)) |
---|
| 44 | { |
---|
| 45 | $this->gs_es = "error #1"; |
---|
| 46 | return(0); |
---|
| 47 | } |
---|
| 48 | /*étude du Logical Screen Descriptor |
---|
| 49 | 7 6 5 4 3 2 1 0 Field Name Type |
---|
| 50 | +---------------+ |
---|
| 51 | 0 | | Logical Screen Width Unsigned |
---|
| 52 | +- -+ |
---|
| 53 | 1 | | |
---|
| 54 | +---------------+ |
---|
| 55 | 2 | | Logical Screen Height Unsigned |
---|
| 56 | +- -+ |
---|
| 57 | 3 | | |
---|
| 58 | +---------------+ |
---|
| 59 | 4 | | | | | <Packed Fields> See below |
---|
| 60 | +---------------+ |
---|
| 61 | 5 | | Background Color Index Byte |
---|
| 62 | +---------------+ |
---|
| 63 | 6 | | Pixel Aspect Ratio Byte |
---|
| 64 | +---------------+ |
---|
| 65 | <Packed Fields> = Global Color Table Flag 1 Bit |
---|
| 66 | Color Resolution 3 Bits |
---|
| 67 | Sort Flag 1 Bit |
---|
| 68 | Size of Global Color Table 3 Bits |
---|
| 69 | */ |
---|
| 70 | //echo "début </br>" ; |
---|
| 71 | $this->getbytes(4); |
---|
| 72 | $this->gs_logical_screen_size = $this->gs_buffer; |
---|
| 73 | |
---|
| 74 | //$this->gs_buffer = array(); |
---|
| 75 | $this->getbytes(3); |
---|
| 76 | $this->gs_logical_screen_descriptor = $this->gs_buffer; |
---|
| 77 | |
---|
| 78 | $this->gs_global_color_table_flag = ($this->gs_buffer[0] & 0x80) ? TRUE : FALSE; |
---|
| 79 | $this->gs_global_color_table_code = ($this->gs_buffer[0] & 0x07); |
---|
| 80 | $this->gs_global_color_table_size = pow(2,($this->gs_global_color_table_code+1)); |
---|
| 81 | //$this->gs_global_color_table_size = 2 << $this->gs_global_color_table_code; |
---|
| 82 | $this->gs_global_sorted = ($this->gs_buffer[4] & 0x08) ? TRUE : FALSE; |
---|
| 83 | if($this->gs_global_color_table_flag) |
---|
| 84 | { |
---|
| 85 | $this->getbytes(3 * $this->gs_global_color_table_size); |
---|
| 86 | for($i = 0; $i < ((3 * $this->gs_global_color_table_size)); $i++) |
---|
| 87 | $this->gs_global_data[$i] = $this->gs_buffer[$i]; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | $this->gs_fou = ''; |
---|
| 92 | |
---|
| 93 | for($loop = true; $loop; ) |
---|
| 94 | { |
---|
| 95 | $this->getbytes(1); |
---|
| 96 | switch($this->gs_buffer[0]) |
---|
| 97 | { |
---|
| 98 | case 0x21: |
---|
| 99 | $this->read_extension(); |
---|
| 100 | break; |
---|
| 101 | case 0x2C: |
---|
| 102 | $this->read_image_descriptor(); |
---|
| 103 | break; |
---|
| 104 | case 0x3B: |
---|
| 105 | $loop = false; |
---|
| 106 | break; |
---|
| 107 | default: |
---|
| 108 | $this->gs_es = sprintf("Unrecognized byte code %u\n<br>", $this->gs_buffer[0]); |
---|
| 109 | } |
---|
| 110 | if (($this->gs_image_count > $this->gs_imnbr)and($this->gs_imnbr > -1)) |
---|
| 111 | { |
---|
| 112 | $loop = false; |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | } |
---|
| 116 | fclose($this->gs_fin); |
---|
| 117 | } |
---|
| 118 | else |
---|
| 119 | { |
---|
| 120 | $this->gs_es = "error #2"; |
---|
| 121 | return(0); |
---|
| 122 | } |
---|
| 123 | $this->gs_es = "ok"; |
---|
| 124 | |
---|
| 125 | } |
---|
| 126 | /*///////////////////////////////////////////////*/ |
---|
| 127 | /*// Function :: read_extension() //*/ |
---|
| 128 | /*///////////////////////////////////////////////*/ |
---|
| 129 | function read_extension() |
---|
| 130 | { |
---|
| 131 | /* Reset global variables */ |
---|
| 132 | /* 0x21 puis 4 bytes discriminants: |
---|
| 133 | 0xF9 : Graphic Control Extension puis 3ème byte Block Size |
---|
| 134 | 0xFE : Comment Extension |
---|
| 135 | 0x01 : Plain Text Extension puis 3ème byte Block Size |
---|
| 136 | 0xFF : Application Extension puis 3ème byte Block Size |
---|
| 137 | 7 6 5 4 3 2 1 0 Field Name Type |
---|
| 138 | +---------------+ |
---|
| 139 | 0 | 0x21 | |
---|
| 140 | +- -+ |
---|
| 141 | 1 | ???? | | 0xF9 | 0xFE | 0x01 | |
---|
| 142 | +---------------+ |
---|
| 143 | 2 | | | Taille | data | Taille | |
---|
| 144 | +- -+ |
---|
| 145 | 3 | | | Data | Data | Data | |
---|
| 146 | | | |
---|
| 147 | | | |
---|
| 148 | +---------------+ |
---|
| 149 | | 0x00 | Block Terminator |
---|
| 150 | +---------------+ |
---|
| 151 | |
---|
| 152 | 7 6 5 4 3 2 1 0 Field Name |
---|
| 153 | +---------------+ |
---|
| 154 | 0 | 0x21 | |
---|
| 155 | +- -+ |
---|
| 156 | 1 | 0xFF | |
---|
| 157 | +---------------+ |
---|
| 158 | 2 | Taille | Taille 1ère extension |
---|
| 159 | +- -+ |
---|
| 160 | 3 | | |
---|
| 161 | | | Data |
---|
| 162 | | | |
---|
| 163 | +- -+ |
---|
| 164 | | Taille | Taille 2ème extension (structure à confirmer) |
---|
| 165 | +- -+ |
---|
| 166 | | | |
---|
| 167 | | | Data |
---|
| 168 | | | |
---|
| 169 | +---------------+ |
---|
| 170 | | 0x00 | Block Terminator |
---|
| 171 | +---------------+ |
---|
| 172 | |
---|
| 173 | */ |
---|
| 174 | $this->gs_fou .="\x21"; |
---|
| 175 | $this->gs_buffer = array(); |
---|
| 176 | $this->getbytes(2); |
---|
| 177 | $this->putbytes($this->gs_buffer, 2); |
---|
| 178 | $this->gs_extension_type = $this->gs_buffer[0]; |
---|
| 179 | $this->gs_extension_lenght=$this->gs_buffer[1]; |
---|
| 180 | if (array_search($this->gs_extension_type, array (1=>0xF9,2=>0x01,3=>0xFF))) |
---|
| 181 | { |
---|
| 182 | $this->getbytes($this->gs_extension_lenght); |
---|
| 183 | $this->putbytes($this->gs_buffer, $this->gs_extension_lenght); |
---|
| 184 | if ($this->gs_extension_type == 0xFF) |
---|
| 185 | { |
---|
| 186 | $this->getbytes(1); |
---|
| 187 | $this->putbytes($this->gs_buffer, 1); |
---|
| 188 | $this->gs_extension_lenght=$this->gs_buffer[0]; |
---|
| 189 | $this->getbytes($this->gs_extension_lenght); |
---|
| 190 | $this->putbytes($this->gs_buffer, $this->gs_extension_lenght); |
---|
| 191 | } |
---|
| 192 | } |
---|
| 193 | for(;;) |
---|
| 194 | { |
---|
| 195 | $this->getbytes(1); |
---|
| 196 | $this->putbytes($this->gs_buffer, 1); |
---|
| 197 | // byte == 0 : fin du data de l'extension |
---|
| 198 | if ($this->gs_buffer[0] == 0) |
---|
| 199 | { |
---|
| 200 | break ; |
---|
| 201 | } |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | /*///////////////////////////////////////////////*/ |
---|
| 208 | /*// Function :: read_image_descriptor() //*/ |
---|
| 209 | /*///////////////////////////////////////////////*/ |
---|
| 210 | function read_image_descriptor() |
---|
| 211 | { |
---|
| 212 | /* Reset global variables */ |
---|
| 213 | $this->gs_buffer = array(); |
---|
| 214 | |
---|
| 215 | //Lecture du descripteur de l'image: Image Descriptor |
---|
| 216 | /* |
---|
| 217 | 7 6 5 4 3 2 1 0 Field Name Type |
---|
| 218 | +---------------+ |
---|
| 219 | 0 | 0x2C | Image Separator Byte |
---|
| 220 | +---------------+ |
---|
| 221 | 1 | | Image Left Position Unsigned |
---|
| 222 | +- -+ |
---|
| 223 | 2 | | |
---|
| 224 | +---------------+ |
---|
| 225 | 3 | | Image Top Position Unsigned |
---|
| 226 | +- -+ |
---|
| 227 | 4 | | |
---|
| 228 | +---------------+ |
---|
| 229 | 5 | | Image Width Unsigned |
---|
| 230 | +- -+ |
---|
| 231 | 6 | | |
---|
| 232 | +---------------+ |
---|
| 233 | 7 | | Image Height Unsigned |
---|
| 234 | +- -+ |
---|
| 235 | 8 | | |
---|
| 236 | +---------------+ |
---|
| 237 | 9 | | | |0 0| | <Packed Fields> See below |
---|
| 238 | +---------------+ |
---|
| 239 | <Packed Fields> = Local Color Table Flag 1 Bit |
---|
| 240 | Interlace Flag 1 Bit |
---|
| 241 | Sort Flag 1 Bit |
---|
| 242 | Reserved 2 Bits |
---|
| 243 | Size of Local Color Table 3 Bits |
---|
| 244 | */ |
---|
| 245 | |
---|
| 246 | $this->gs_fou .="\x2C"; |
---|
| 247 | |
---|
| 248 | $this->getbytes(9); |
---|
| 249 | for($i = 0; $i < 9; $i++) |
---|
| 250 | { |
---|
| 251 | $this->gs_image_descriptor[$i] = $this->gs_buffer[$i]; |
---|
| 252 | } |
---|
| 253 | |
---|
| 254 | if ($this->gs_rsz==1) // new screen sizes and image edges |
---|
| 255 | { |
---|
| 256 | // new logical screen size |
---|
| 257 | $this->gs_logical_screen_size[0] = $this->gs_image_descriptor[4]; |
---|
| 258 | $this->gs_logical_screen_size[1] = $this->gs_image_descriptor[5]; |
---|
| 259 | $this->gs_logical_screen_size[2] = $this->gs_image_descriptor[6]; |
---|
| 260 | $this->gs_logical_screen_size[3] = $this->gs_image_descriptor[7]; |
---|
| 261 | // reset position |
---|
| 262 | $this->gs_image_descriptor[0] = $this->gs_image_descriptor[1] = $this->gs_image_descriptor[2] = $this->gs_image_descriptor[3] = 0; |
---|
| 263 | } |
---|
| 264 | $this->putbytes($this->gs_image_descriptor, 9); |
---|
| 265 | |
---|
| 266 | $local_color_table_flag = ($this->gs_buffer[8] & 0x80) ? TRUE : FALSE; |
---|
| 267 | |
---|
| 268 | if($local_color_table_flag) |
---|
| 269 | { |
---|
| 270 | //il y a une table locale des couleurs |
---|
| 271 | $code = ($this->gs_buffer[8] & 0x07); |
---|
| 272 | $sorted = ($this->gs_buffer[8] & 0x20) ? TRUE : FALSE; |
---|
| 273 | $size = pow(2,($code+1)); |
---|
| 274 | } |
---|
| 275 | |
---|
| 276 | if($local_color_table_flag) |
---|
| 277 | { |
---|
| 278 | $this->getbytes(3 * $size); |
---|
| 279 | $this->putbytes($this->gs_buffer, 3 * $size); |
---|
| 280 | } |
---|
| 281 | /* LZW minimum code size */ |
---|
| 282 | $this->getbytes(1); |
---|
| 283 | $this->putbytes($this->gs_buffer, 1); |
---|
| 284 | |
---|
| 285 | /* Image Data */ |
---|
| 286 | for(;;) |
---|
| 287 | { |
---|
| 288 | $this->getbytes(1); |
---|
| 289 | $this->putbytes($this->gs_buffer, 1); |
---|
| 290 | if(($u = $this->gs_buffer[0]) == 0) |
---|
| 291 | break; |
---|
| 292 | $this->getbytes($u); |
---|
| 293 | $this->putbytes($this->gs_buffer, $u); |
---|
| 294 | } |
---|
| 295 | |
---|
| 296 | $this->gs_global_image_data = $this->gs_fou; |
---|
| 297 | |
---|
| 298 | //Construction de la structure de tête du fichier |
---|
| 299 | |
---|
| 300 | // Header -> GIF89a // |
---|
| 301 | $this->gs_fou = $this->gs_header; |
---|
| 302 | |
---|
| 303 | //logical_screen_descriptor// |
---|
| 304 | $this->putbytes($this->gs_logical_screen_size,4); |
---|
| 305 | $this->putbytes($this->gs_logical_screen_descriptor,3); |
---|
| 306 | |
---|
| 307 | //Global Color Table// |
---|
| 308 | $this->putbytes($this->gs_global_data, $this->gs_global_color_table_size*3); |
---|
| 309 | |
---|
| 310 | //Global_image_data |
---|
| 311 | |
---|
| 312 | $this->gs_fou .= $this->gs_global_image_data; |
---|
| 313 | |
---|
| 314 | /* trailer */ |
---|
| 315 | $this->gs_fou .= "\x3B"; |
---|
| 316 | |
---|
| 317 | |
---|
| 318 | |
---|
| 319 | |
---|
| 320 | /* Write to file */ |
---|
| 321 | switch($this->gs_fm) |
---|
| 322 | { |
---|
| 323 | case "GIF": |
---|
| 324 | //Enregistrement du fichier gif |
---|
| 325 | $framename = $this->gs_sp . $this->gs_image_count . ".gif"; |
---|
| 326 | if (!$handle = fopen($framename, 'w')) { |
---|
| 327 | echo "Impossible d'ouvrir le fichier ($framename)"; |
---|
| 328 | exit; |
---|
| 329 | } |
---|
| 330 | |
---|
| 331 | if(!fwrite($handle,$this->gs_fou)) |
---|
| 332 | { |
---|
| 333 | $this->gs_es = "error #3"; |
---|
| 334 | return(0); |
---|
| 335 | } |
---|
| 336 | |
---|
| 337 | $this->gs_fileframe[]=$framename; |
---|
| 338 | break; |
---|
| 339 | /* Write as BMP */ |
---|
| 340 | case "BMP": |
---|
| 341 | $im = imageCreateFromString($this->gs_fou); |
---|
| 342 | $framename = $this->gs_sp . $this->gs_image_count . ".bmp"; |
---|
| 343 | if(!$this->imageBmp($im, $framename)) |
---|
| 344 | { |
---|
| 345 | $this->gs_es = "error #3"; |
---|
| 346 | return(0); |
---|
| 347 | } |
---|
| 348 | imageDestroy($im); |
---|
| 349 | break; |
---|
| 350 | /* Write as PNG */ |
---|
| 351 | case "PNG": |
---|
| 352 | $im = imageCreateFromString($this->gs_fou); |
---|
| 353 | $framename = $this->gs_sp . $this->gs_image_count . ".png"; |
---|
| 354 | if(!imagePng($im, $framename)) |
---|
| 355 | { |
---|
| 356 | $this->gs_es = "error #3"; |
---|
| 357 | return(0); |
---|
| 358 | } |
---|
| 359 | imageDestroy($im); |
---|
| 360 | break; |
---|
| 361 | /* Write as JPG */ |
---|
| 362 | case "JPG": |
---|
| 363 | $im = imageCreateFromString($this->gs_fou); |
---|
| 364 | $framename = $this->gs_sp . $this->gs_image_count . ".jpg"; |
---|
| 365 | if(!imageJpeg($im, $framename)) |
---|
| 366 | { |
---|
| 367 | $this->gs_es = "error #3"; |
---|
| 368 | return(0); |
---|
| 369 | } |
---|
| 370 | imageDestroy($im); |
---|
| 371 | break; |
---|
| 372 | /* Write as GIF */ |
---|
| 373 | case "GIF": |
---|
| 374 | $im = imageCreateFromString($this->gs_fou); |
---|
| 375 | |
---|
| 376 | imageDestroy($im); |
---|
| 377 | |
---|
| 378 | break; |
---|
| 379 | } |
---|
| 380 | $this->gs_image_count++; |
---|
| 381 | $this->gs_fou = ''; |
---|
| 382 | } |
---|
| 383 | /*///////////////////////////////////////////////*/ |
---|
| 384 | /*// BMP creation group //*/ |
---|
| 385 | /*///////////////////////////////////////////////*/ |
---|
| 386 | /* ImageBMP */ |
---|
| 387 | function imageBmp($img, $file, $RLE=0) |
---|
| 388 | { |
---|
| 389 | $ColorCount = imagecolorstotal($img); |
---|
| 390 | $Transparent = imagecolortransparent($img); |
---|
| 391 | $IsTransparent = $Transparent != -1; |
---|
| 392 | if($IsTransparent) |
---|
| 393 | $ColorCount--; |
---|
| 394 | if($ColorCount == 0) |
---|
| 395 | { |
---|
| 396 | $ColorCount = 0; |
---|
| 397 | $BitCount = 24; |
---|
| 398 | } |
---|
| 399 | if(($ColorCount > 0) && ($ColorCount <= 2)) |
---|
| 400 | { |
---|
| 401 | $ColorCount = 2; |
---|
| 402 | $BitCount = 1; |
---|
| 403 | } |
---|
| 404 | if(($ColorCount > 2) && ($ColorCount <= 16)) |
---|
| 405 | { |
---|
| 406 | $ColorCount = 16; |
---|
| 407 | $BitCount = 4; |
---|
| 408 | } |
---|
| 409 | if(($ColorCount > 16) && ($ColorCount <= 256)) |
---|
| 410 | { |
---|
| 411 | $ColorCount = 0; |
---|
| 412 | $BitCount = 8; |
---|
| 413 | } |
---|
| 414 | $Width = imageSX($img); |
---|
| 415 | $Height = imageSY($img); |
---|
| 416 | $Zbytek = (4 - ($Width / (8 / $BitCount)) % 4) % 4; |
---|
| 417 | if($BitCount < 24) |
---|
| 418 | $palsize = pow(2, $BitCount) * 4; |
---|
| 419 | $size = (floor($Width / (8 / $BitCount)) + $Zbytek) * $Height + 54; |
---|
| 420 | $size += $palsize; |
---|
| 421 | $offset = 54 + $palsize; |
---|
| 422 | // Bitmap File Header |
---|
| 423 | $ret = 'BM'; |
---|
| 424 | $ret .= $this->int_to_dword($size); |
---|
| 425 | $ret .= $this->int_to_dword(0); |
---|
| 426 | $ret .= $this->int_to_dword($offset); |
---|
| 427 | // Bitmap Info Header |
---|
| 428 | $ret .= $this->int_to_dword(40); |
---|
| 429 | $ret .= $this->int_to_dword($Width); |
---|
| 430 | $ret .= $this->int_to_dword($Height); |
---|
| 431 | $ret .= $this->int_to_word(1); |
---|
| 432 | $ret .= $this->int_to_word($BitCount); |
---|
| 433 | $ret .= $this->int_to_dword($RLE); |
---|
| 434 | $ret .= $this->int_to_dword(0); |
---|
| 435 | $ret .= $this->int_to_dword(0); |
---|
| 436 | $ret .= $this->int_to_dword(0); |
---|
| 437 | $ret .= $this->int_to_dword(0); |
---|
| 438 | $ret .= $this->int_to_dword(0); |
---|
| 439 | // image data |
---|
| 440 | $CC = $ColorCount; |
---|
| 441 | $sl1 = strlen($ret); |
---|
| 442 | if($CC == 0) |
---|
| 443 | $CC = 256; |
---|
| 444 | if($BitCount < 24) |
---|
| 445 | { |
---|
| 446 | $ColorTotal = imagecolorstotal($img); |
---|
| 447 | if($IsTransparent) |
---|
| 448 | $ColorTotal--; |
---|
| 449 | for($p = 0; $p < $ColorTotal; $p++) |
---|
| 450 | { |
---|
| 451 | $color = imagecolorsforindex($img, $p); |
---|
| 452 | $ret .= $this->inttobyte($color["blue"]); |
---|
| 453 | $ret .= $this->inttobyte($color["green"]); |
---|
| 454 | $ret .= $this->inttobyte($color["red"]); |
---|
| 455 | $ret .= $this->inttobyte(0); |
---|
| 456 | } |
---|
| 457 | $CT = $ColorTotal; |
---|
| 458 | for($p = $ColorTotal; $p < $CC; $p++) |
---|
| 459 | { |
---|
| 460 | $ret .= $this->inttobyte(0); |
---|
| 461 | $ret .= $this->inttobyte(0); |
---|
| 462 | $ret .= $this->inttobyte(0); |
---|
| 463 | $ret .= $this->inttobyte(0); |
---|
| 464 | } |
---|
| 465 | } |
---|
| 466 | if($BitCount <= 8) |
---|
| 467 | { |
---|
| 468 | for($y = $Height - 1; $y >= 0; $y--) |
---|
| 469 | { |
---|
| 470 | $bWrite = ""; |
---|
| 471 | for($x = 0; $x < $Width; $x++) |
---|
| 472 | { |
---|
| 473 | $color = imagecolorat($img, $x, $y); |
---|
| 474 | $bWrite .= $this->decbinx($color, $BitCount); |
---|
| 475 | if(strlen($bWrite) == 8) |
---|
| 476 | { |
---|
| 477 | $retd .= $this->inttobyte(bindec($bWrite)); |
---|
| 478 | $bWrite = ""; |
---|
| 479 | } |
---|
| 480 | } |
---|
| 481 | if((strlen($bWrite) < 8) and (strlen($bWrite) != 0)) |
---|
| 482 | { |
---|
| 483 | $sl = strlen($bWrite); |
---|
| 484 | for($t = 0; $t < 8 - $sl; $t++) |
---|
| 485 | $sl .= "0"; |
---|
| 486 | $retd .= $this->inttobyte(bindec($bWrite)); |
---|
| 487 | } |
---|
| 488 | for($z = 0; $z < $Zbytek; $z++) |
---|
| 489 | $retd .= $this->inttobyte(0); |
---|
| 490 | } |
---|
| 491 | } |
---|
| 492 | if(($RLE == 1) and ($BitCount == 8)) |
---|
| 493 | { |
---|
| 494 | for($t = 0; $t < strlen($retd); $t += 4) |
---|
| 495 | { |
---|
| 496 | if($t != 0) |
---|
| 497 | if(($t) % $Width == 0) |
---|
| 498 | $ret .= chr(0).chr(0); |
---|
| 499 | if(($t + 5) % $Width == 0) |
---|
| 500 | { |
---|
| 501 | $ret .= chr(0).chr(5).substr($retd, $t, 5).chr(0); |
---|
| 502 | $t += 1; |
---|
| 503 | } |
---|
| 504 | if(($t + 6) % $Width == 0) |
---|
| 505 | { |
---|
| 506 | $ret .= chr(0).chr(6).substr($retd, $t, 6); |
---|
| 507 | $t += 2; |
---|
| 508 | } |
---|
| 509 | else |
---|
| 510 | $ret .= chr(0).chr(4).substr($retd, $t, 4); |
---|
| 511 | } |
---|
| 512 | $ret .= chr(0).chr(1); |
---|
| 513 | } |
---|
| 514 | else |
---|
| 515 | $ret .= $retd; |
---|
| 516 | if($BitCount == 24) |
---|
| 517 | { |
---|
| 518 | for($z = 0; $z < $Zbytek; $z++) |
---|
| 519 | $Dopl .= chr(0); |
---|
| 520 | for($y = $Height - 1; $y >= 0; $y--) |
---|
| 521 | { |
---|
| 522 | for($x = 0; $x < $Width; $x++) |
---|
| 523 | { |
---|
| 524 | $color = imagecolorsforindex($img, ImageColorAt($img, $x, $y)); |
---|
| 525 | $ret .= chr($color["blue"]).chr($color["green"]).chr($color["red"]); |
---|
| 526 | } |
---|
| 527 | $ret .= $Dopl; |
---|
| 528 | } |
---|
| 529 | } |
---|
| 530 | if(fwrite(fopen($file, "wb"), $ret)) |
---|
| 531 | return true; |
---|
| 532 | else |
---|
| 533 | return false; |
---|
| 534 | } |
---|
| 535 | /* INT 2 WORD */ |
---|
| 536 | function int_to_word($n) |
---|
| 537 | { |
---|
| 538 | return chr($n & 255).chr(($n >> 8) & 255); |
---|
| 539 | } |
---|
| 540 | /* INT 2 DWORD */ |
---|
| 541 | function int_to_dword($n) |
---|
| 542 | { |
---|
| 543 | return chr($n & 255).chr(($n >> 8) & 255).chr(($n >> 16) & 255).chr(($n >> 24) |
---|
| 544 | & 255); } |
---|
| 545 | /* INT 2 BYTE */ |
---|
| 546 | function inttobyte($n) |
---|
| 547 | { |
---|
| 548 | return chr($n); |
---|
| 549 | } |
---|
| 550 | /* DECIMAL 2 BIN */ |
---|
| 551 | function decbinx($d,$n) |
---|
| 552 | { |
---|
| 553 | $bin = decbin($d); |
---|
| 554 | $sbin = strlen($bin); |
---|
| 555 | for($j = 0; $j < $n - $sbin; $j++) |
---|
| 556 | $bin = "0$bin"; |
---|
| 557 | return $bin; |
---|
| 558 | } |
---|
| 559 | /*///////////////////////////////////////////////*/ |
---|
| 560 | /*// Function :: arrcmp() //*/ |
---|
| 561 | /*///////////////////////////////////////////////*/ |
---|
| 562 | function arrcmp($b, $s, $l) |
---|
| 563 | { |
---|
| 564 | for($i = 0; $i < $l; $i++) |
---|
| 565 | { |
---|
| 566 | if($s{$i} != $b{$i}) return false; |
---|
| 567 | } |
---|
| 568 | return true; |
---|
| 569 | } |
---|
| 570 | /*///////////////////////////////////////////////*/ |
---|
| 571 | /*// Function :: getbytes() //*/ |
---|
| 572 | /*///////////////////////////////////////////////*/ |
---|
| 573 | function getbytes($l) |
---|
| 574 | { |
---|
| 575 | for($i = 0; $i < $l; $i++) |
---|
| 576 | { |
---|
| 577 | $bin = unpack('C*', fread($this->gs_fin, 1)); |
---|
| 578 | $this->gs_buffer[$i] = $bin[1]; |
---|
| 579 | } |
---|
| 580 | return $this->gs_buffer; |
---|
| 581 | } |
---|
| 582 | /*///////////////////////////////////////////////*/ |
---|
| 583 | /*// Function :: putbytes() //*/ |
---|
| 584 | /*///////////////////////////////////////////////*/ |
---|
| 585 | function putbytes($s, $l) |
---|
| 586 | { |
---|
| 587 | for($i = 0; $i < $l; $i++) |
---|
| 588 | { |
---|
| 589 | $this->gs_fou .= pack('C*', $s[$i]); |
---|
| 590 | } |
---|
| 591 | } |
---|
| 592 | function getFilelist() |
---|
| 593 | { |
---|
| 594 | return $this->gs_fileframe; |
---|
| 595 | } |
---|
| 596 | |
---|
| 597 | function getReport() |
---|
| 598 | { |
---|
| 599 | return $this->gs_es; |
---|
| 600 | } |
---|
| 601 | } |
---|
| 602 | ?> |
---|