[ PHPXref.com ] [ Generated: Sun Jul 20 19:56:57 2008 ] [ phpThumb() 1.7.1 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/ -> phpthumb.ico.php (source)

   1  <?php
   2  //////////////////////////////////////////////////////////////
   3  ///  phpThumb() by James Heinrich <info@silisoftware.com>   //
   4  //        available at http://phpthumb.sourceforge.net     ///
   5  //////////////////////////////////////////////////////////////
   6  ///                                                         //
   7  // phpthumb.ico.php - .ICO output format functions          //
   8  //                                                         ///
   9  //////////////////////////////////////////////////////////////
  10  
  11  
  12  class phpthumb_ico {
  13  
  14  	function phpthumb_ico() {
  15          return true;
  16      }
  17  
  18  
  19  	function GD2ICOstring(&$gd_image_array) {
  20          foreach ($gd_image_array as $key => $gd_image) {
  21  
  22              $ImageWidths[$key]  = ImageSX($gd_image);
  23              $ImageHeights[$key] = ImageSY($gd_image);
  24              $bpp[$key]          = ImageIsTrueColor($gd_image) ? 32 : 24;
  25              $totalcolors[$key]  = ImageColorsTotal($gd_image);
  26  
  27              $icXOR[$key] = '';
  28              for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
  29                  for ($x = 0; $x < $ImageWidths[$key]; $x++) {
  30                      $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
  31                      $a = round(255 * ((127 - $argb['alpha']) / 127));
  32                      $r = $argb['red'];
  33                      $g = $argb['green'];
  34                      $b = $argb['blue'];
  35  
  36                      if ($bpp[$key] == 32) {
  37                          $icXOR[$key] .= chr($b).chr($g).chr($r).chr($a);
  38                      } elseif ($bpp[$key] == 24) {
  39                          $icXOR[$key] .= chr($b).chr($g).chr($r);
  40                      }
  41  
  42                      if ($a < 128) {
  43                          @$icANDmask[$key][$y] .= '1';
  44                      } else {
  45                          @$icANDmask[$key][$y] .= '0';
  46                      }
  47                  }
  48                  // mask bits are 32-bit aligned per scanline
  49                  while (strlen($icANDmask[$key][$y]) % 32) {
  50                      $icANDmask[$key][$y] .= '0';
  51                  }
  52              }
  53              $icAND[$key] = '';
  54              foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
  55                  for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
  56                      $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
  57                  }
  58              }
  59  
  60          }
  61  
  62          foreach ($gd_image_array as $key => $gd_image) {
  63              $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
  64  
  65              // BITMAPINFOHEADER - 40 bytes
  66              $BitmapInfoHeader[$key]  = '';
  67              $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                              // DWORD  biSize;
  68              $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);      // LONG   biWidth;
  69              // The biHeight member specifies the combined
  70              // height of the XOR and AND masks.
  71              $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
  72              $BitmapInfoHeader[$key] .= "\x01\x00";                                      // WORD   biPlanes;
  73                 $BitmapInfoHeader[$key] .= chr($bpp[$key])."\x00";                          // wBitCount;
  74              $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                              // DWORD  biCompression;
  75              $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);            // DWORD  biSizeImage;
  76              $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                              // LONG   biXPelsPerMeter;
  77              $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                              // LONG   biYPelsPerMeter;
  78              $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                              // DWORD  biClrUsed;
  79              $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                              // DWORD  biClrImportant;
  80          }
  81  
  82  
  83          $icondata  = "\x00\x00";                                      // idReserved;   // Reserved (must be 0)
  84          $icondata .= "\x01\x00";                                      // idType;       // Resource Type (1 for icons)
  85          $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;      // How many images?
  86  
  87          $dwImageOffset = 6 + (count($gd_image_array) * 16);
  88          foreach ($gd_image_array as $key => $gd_image) {
  89              // ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
  90  
  91              $icondata .= chr($ImageWidths[$key]);                     // bWidth;          // Width, in pixels, of the image
  92              $icondata .= chr($ImageHeights[$key]);                    // bHeight;         // Height, in pixels, of the image
  93              $icondata .= chr($totalcolors[$key]);                     // bColorCount;     // Number of colors in image (0 if >=8bpp)
  94              $icondata .= "\x00";                                      // bReserved;       // Reserved ( must be 0)
  95  
  96              $icondata .= "\x01\x00";                                  // wPlanes;         // Color Planes
  97              $icondata .= chr($bpp[$key])."\x00";                      // wBitCount;       // Bits per pixel
  98  
  99              $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
 100              $icondata .= phpthumb_functions::LittleEndian2String($dwBytesInRes, 4);       // dwBytesInRes;    // How many bytes in this resource?
 101  
 102              $icondata .= phpthumb_functions::LittleEndian2String($dwImageOffset, 4);      // dwImageOffset;   // Where in the file is this image?
 103              $dwImageOffset += strlen($BitmapInfoHeader[$key]);
 104              $dwImageOffset += strlen($icXOR[$key]);
 105              $dwImageOffset += strlen($icAND[$key]);
 106          }
 107  
 108          foreach ($gd_image_array as $key => $gd_image) {
 109              $icondata .= $BitmapInfoHeader[$key];
 110              $icondata .= $icXOR[$key];
 111              $icondata .= $icAND[$key];
 112          }
 113  
 114          return $icondata;
 115      }
 116  
 117  }
 118  
 119  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]