当前位置: 绿色php资源 > php开源 > 代码片段 >

php在线生成ico代码

时间:2010-11-27 16:26 作者:php开源 点击:
请下载附件中的源码不要直接复制 (已下载 672 次) ?php ////////////////////////////////////////////////////////////// ///phpThumb()byJamesheinrichinfo@silisoftware.com// //phpzy.com //availableathttp://phpthumb.sourceforge.ne

   请下载附件中的源码,不要直接复制 (已下载 672 次)


<?php
//////////////////////////////////////////////////////////////
///  phpThumb() by James heinrich <info@silisoftware.com>   // //phpzy.com
//        available at http://phpthumb.sourceforge.net     ///
//////////////////////////////////////////////////////////////
///                                                         //
// phpthumb.ico.php - .Ico output format functions          //
//                                                         /// //phpzy.coM
//////////////////////////////////////////////////////////////


class phpthumb_ico {

    function phpthumb_ico() {
        return true;
    }


    function GD2Icostring(&$gd_image_array) {
        foreach ($gd_image_array as $key => $gd_image) { //phpzy.coM开源

            $ImageWidths  = ImagesX($gd_image);
            $Imageheights = ImagesY($gd_image);
            $bpp          = ImageIsTruecolor($gd_image) ? 32 : 24; //开源phpzy.coM
            $totalcolors  = ImagecolorsTotal($gd_image);

            $icXoR = '';
            for ($y = $Imageheights - 1; $y >= 0; $y--) { //php开源代码
                for ($x = 0; $x < $ImageWidths; $x++) {
                    $argb = phpthumb_functions::Getpixelcolor($gd_image, $x, $y); //php开源代码
                    $a = round(255 * ((127 - $argb) / 127));
                    $r = $argb; //phpzy.coM开源
                    $g = $argb;
                    $b = $argb;

                    if ($bpp == 32) { //phpzy.coM开源
                        $icXoR .= chr($b).chr($g).chr($r).chr($a);
                    } elseif ($bpp == 24) { //开源代码phpzy.coM
                        $icXoR .= chr($b).chr($g).chr($r);
                    }

                    if ($a < 128) { //开源代码phpzy.coM
                        @$icAnDmask .= '1';
                    } else {
                        @$icAnDmask .= '0'; //phpzy.com
                    }
                }
                // mask bits are 32-bit aligned per scanline
                while (strlen($icAnDmask) % 32) {
                    $icAnDmask .= '0';

//开源代码phpzy.com


                }
            }
            $icAnD = '';
            foreach ($icAnDmask as $y => $scanlinemaskbits) {
                for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) { //php开源代码
                    $icAnD .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', sTR_pAD_LEFT)));

//php开源代码


                }
            }

        }

        foreach ($gd_image_array as $key => $gd_image) {
            $bisizeImage = $ImageWidths * $Imageheights * ($bpp / 8); //phpzy.com

            // BITMApInFohEADER - 40 bytes
            $BitmapInfoheader  = '';
            $BitmapInfoheader .= "x28x00x00x00";                              // DWoRD  bisize; //phpzy.coM
            $BitmapInfoheader .= phpthumb_functions::LittleEndian2string($ImageWidths, 4);      // LonG   biWidth;
            // The biheight member specifies the combined
            // height of the XoR and AnD masks.

//phpzy.coM


            $BitmapInfoheader .= phpthumb_functions::LittleEndian2string($Imageheights * 2, 4); // LonG   biheight;
            $BitmapInfoheader .= "x01x00";                                      // WoRD   biplanes; //php开源代码
               $BitmapInfoheader .= chr($bpp)."x00";                          // wBitcount;
            $BitmapInfoheader .= "x00x00x00x00";                              // DWoRD  bicompression; //开源代码phpzy.coM
            $BitmapInfoheader .= phpthumb_functions::LittleEndian2string($bisizeImage, 4);            // DWoRD  bisizeImage;
            $BitmapInfoheader .= "x00x00x00x00";                              // LonG   biXpelsperMeter; //phpzy.com
            $BitmapInfoheader .= "x00x00x00x00";                              // LonG   biYpelsperMeter;
            $BitmapInfoheader .= "x00x00x00x00";                              // DWoRD  biclrUsed; //phpzy.com
            $BitmapInfoheader .= "x00x00x00x00";                              // DWoRD  biclrImportant;
        }


        $icondata  = "x00x00";                                      // idReserved;   // Reserved (must be 0)

//phpzy.com


        $icondata .= "x01x00";                                      // idType;       // Resource Type (1 for icons)
        $icondata .= phpthumb_functions::LittleEndian2string(count($gd_image_array), 2);  // idcount;      // how many images? //phpzy.com

        $dwImageoffset = 6 + (count($gd_image_array) * 16);
        foreach ($gd_image_array as $key => $gd_image) {
            // IconDIREnTRY   idEntries; // An entry for each image (idcount of 'em) //phpzy.com

            $icondata .= chr($ImageWidths);                     // bWidth;          // Width, in pixels, of the image
            $icondata .= chr($Imageheights);                    // bheight;         // height, in pixels, of the image

//phpzy.com


            $icondata .= chr($totalcolors);                     // bcolorcount;     // number of colors in image (0 if >=8bpp)
            $icondata .= "x00";                                      // bReserved;       // Reserved ( must be 0) //开源phpzy.coM

            $icondata .= "x01x00";                                  // wplanes;         // color planes
            $icondata .= chr($bpp)."x00";                      // wBitcount;       // Bits per pixel //phpzy.coM开源

            $dwBytesInRes = 40 + strlen($icXoR) + strlen($icAnD);
            $icondata .= phpthumb_functions::LittleEndian2string($dwBytesInRes, 4);       // dwBytesInRes;    // how many bytes in this resource? //phpzy.coM开源

            $icondata .= phpthumb_functions::LittleEndian2string($dwImageoffset, 4);      // dwImageoffset;   // Where in the file is this image?
            $dwImageoffset += strlen($BitmapInfoheader);

//开源代码phpzy.com


            $dwImageoffset += strlen($icXoR);
            $dwImageoffset += strlen($icAnD);
        }

        foreach ($gd_image_array as $key => $gd_image) { //phpzy.coM
            $icondata .= $BitmapInfoheader;
            $icondata .= $icXoR;
            $icondata .= $icAnD;
        } //phpzy.com

        return $icondata;
    }

}

?> 

标签(Tag):
------分隔线----------------------------
  • 上一篇:Auto Ajax
  • 下一篇:没有了
推荐内容
热点内容