Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.43 KB | None | 0 0
  1. <?php
  2.  
  3.     // FUNÇAO PARA CONVERTER
  4.     function imagecreatefrombmpstring($im)
  5.     {
  6.         $header = unpack("vtype/Vsize/v2reserved/Voffset", substr($im, 0, 14));
  7.         $info = unpack("Vsize/Vwidth/Vheight/vplanes/vbits/Vcompression/Vimagesize/Vxres/Vyres/Vncolor/Vimportant", substr($im, 14, 40));
  8.         extract($info);
  9.         extract($header);
  10.         if($type != 0x4D42)
  11.             return false;
  12.         $palette_size = $offset - 54;
  13.         $ncolor = $palette_size / 4;
  14.         $imres=imagecreatetruecolor($width, $height);
  15.         imagealphablending($imres, false);
  16.         imagesavealpha($imres, true);
  17.         $pal=array();
  18.         if($palette_size) {
  19.             $palette = substr($im, 54, $palette_size);
  20.             $gd_palette = "";
  21.             $j = 0; $n = 0;
  22.             while($j < $palette_size) {
  23.                 $b = ord($palette{$j++});
  24.                 $g = ord($palette{$j++});
  25.                 $r = ord($palette{$j++});
  26.                 $a = ord($palette{$j++});
  27.                 if ( ($r == 255) && ($g == 0) && ($b == 255))
  28.                     $a = 127; // alpha = 255 on 0xFF00FF
  29.                 $pal[$n++] = imagecolorallocatealpha($imres, $r, $g, $b, $a);
  30.             }
  31.         }
  32.         $scan_line_size = (($bits * $width) + 7) >> 3;
  33.         $scan_line_align = ($scan_line_size & 0x03) ? 4 - ($scan_line_size & 0x03): 0;
  34.         for($i = 0, $l = $height - 1; $i < $height; $i++, $l--) {
  35.             $scan_line = substr($im, $offset + (($scan_line_size + $scan_line_align) * $l), $scan_line_size);
  36.             if($bits == 24) {
  37.                 $j = 0; $n = 0;
  38.                 while($j < $scan_line_size) {
  39.                     $b = ord($scan_line{$j++});
  40.                     $g = ord($scan_line{$j++});
  41.                     $r = ord($scan_line{$j++});
  42.                     $a = 0;
  43.                     if ( ($r == 255) && ($g == 0) && ($b == 255))
  44.                         $a = 127; // alpha = 255 on 0xFF00FF
  45.                     $col=imagecolorallocatealpha($imres, $r, $g, $b, $a);
  46.                     imagesetpixel($imres, $n++, $i, $col);
  47.                 }
  48.             }
  49.             else if($bits == 8) {
  50.                 $j = 0;
  51.                 while($j < $scan_line_size) {
  52.                     $col = $pal[ord($scan_line{$j++})];
  53.                     imagesetpixel($imres, $j-1, $i, $col);
  54.                 }
  55.             }
  56.             else if($bits == 4) {
  57.                 $j = 0; $n = 0;
  58.                 while($j < $scan_line_size) {
  59.                     $byte = ord($scan_line{$j++});
  60.                     $p1 = $byte >> 4;
  61.                     $p2 = $byte & 0x0F;
  62.                     imagesetpixel($imres, $n++, $i, $pal[$p1]);
  63.                     imagesetpixel($imres, $n++, $i, $pal[$p2]);
  64.                 }
  65.             }
  66.             else if($bits == 1) {
  67.                 $j = 0; $n = 0;
  68.                 while($j < $scan_line_size) {
  69.                     $byte = ord($scan_line{$j++});
  70.                     $p1 = (int) (($byte & 0x80) != 0);
  71.                     $p2 = (int) (($byte & 0x40) != 0);
  72.                     $p3 = (int) (($byte & 0x20) != 0);
  73.                     $p4 = (int) (($byte & 0x10) != 0);
  74.                     $p5 = (int) (($byte & 0x08) != 0);
  75.                     $p6 = (int) (($byte & 0x04) != 0);
  76.                     $p7 = (int) (($byte & 0x02) != 0);
  77.                     $p8 = (int) (($byte & 0x01) != 0);
  78.                     imagesetpixel($imres, $n++, $i, $pal[$p1]);
  79.                     imagesetpixel($imres, $n++, $i, $pal[$p2]);
  80.                     imagesetpixel($imres, $n++, $i, $pal[$p3]);
  81.                     imagesetpixel($imres, $n++, $i, $pal[$p4]);
  82.                     imagesetpixel($imres, $n++, $i, $pal[$p5]);
  83.                     imagesetpixel($imres, $n++, $i, $pal[$p6]);
  84.                     imagesetpixel($imres, $n++, $i, $pal[$p7]);
  85.                     imagesetpixel($imres, $n++, $i, $pal[$p8]);
  86.                 }
  87.             }
  88.         }
  89.         return $imres;
  90.     }
  91.    
  92.     // Pega o ID VIA GET
  93.     $id = $_GET['id'];
  94.    
  95.     // Faça uma consulta e retorne o emblem_data  na váriavel emblem!
  96.    
  97.     $emblem = RETORNO_DO_EMBLEM_DATA;
  98.     $ebm = @gzuncompress(pack('H*', $emblem));
  99.     if( function_exists("gd_info") )
  100.     {
  101.         $im = imagecreatefrombmpstring($ebm);
  102.        
  103.         header('Content-Type: image/png', true);
  104.         imagepng($im);
  105.         imagedestroy($im);
  106.     } else {
  107.         header('Content-Type: image/bitmap', true);
  108.         echo $ebm;
  109.     }
  110. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement