国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PHP > 正文

在線生成favicon.ico或ico圖標源碼

2024-05-04 23:00:21
字體:
供稿:網(wǎng)友


php在線生成ico文件源代碼.

favicon圖標介紹

favicon.ico一般用于作為縮略的網(wǎng)站標志,它顯示位于瀏覽器的地址欄或者在標簽上,用于顯示網(wǎng)站的logo,如圖紅圈的位置, 目前主要的瀏覽器都支持favicon.ico圖標.


以下是index.php源代碼
<?php 
$output = ""; 
if(isset($_get[’action’])&&$_get[’action’] == ’make’){ 
    if(isset($_files[’upimage’][’tmp_name’]) && $_files[’upimage’][’tmp_name’] && is_uploaded_file($_files[’upimage’][’tmp_name’])){ 
        if($_files[’upimage’][’type’]>210000){ 
            echo "你上傳的文件體積超過了限制 最大不能超過200k"; 
            exit(); 
        } 
        $fileext = array("image/pjpeg","image/gif","image/x-png"); 
        if(!in_array($_files[’upimage’][’type’],$fileext)){ 
            echo "你上傳的文件格式不正確 僅支持 jpg,gif,png"; 
            exit(); 
        } 
        if($im = @imagecreatefrompng($_files[’upimage’][’tmp_name’]) or $im = @imagecreatefromgif($_files[’upimage’][’tmp_name’]) or $im = @imagecreatefromjpeg($_files[’upimage’][’tmp_name’])){ 
            $imginfo = @getimagesize($_files[’upimage’][’tmp_name’]); 
            if(!is_array($imginfo)){ 
                echo "圖形格式錯誤!"; 
            } 
            switch($_post[’size’]){ 
                case 1; 
                    $resize_im = @imagecreatetruecolor(16,16); 
                    $size = 16; 
                    break; 
                case 2; 
                    $resize_im = @imagecreatetruecolor(32,32); 
                    $size = 32; 
                    break; 
                case 3; 
                    $resize_im = @imagecreatetruecolor(48,48); 
                    $size = 48; 
                    break; 
                default; 
                    $resize_im = @imagecreatetruecolor(32,32); 
                    $size = 32; 
                    break; 
            } 
            imagecopyresampled($resize_im,$im,0,0,0,0,$size,$size,$imginfo[0],$imginfo[1]); 
            include "phpthumb.ico.php"; 
            $icon = new phpthumb_ico(); 
            $gd_image_array = array($resize_im); 
            $icon_data = $icon->gd2icostring($gd_image_array); 
            $filename = "temp/".date("ymdhis").rand(1,1000).".ico"; 
            if(file_put_contents($filename, $icon_data)){ 
                $output = "生成成功!請點右鍵->另存為 保存到本地<br><a href=/"".$filename."/" target=/"_blank/">點擊下載</a>"; 
            } 
        }else{ 
            echo "生成錯誤請重試!"; 
        } 
    }     

?> 
<html> 
<head> 
<title>ico圖標在線轉(zhuǎn)換</title> 
<style> 
body{background-color:#fff;color:#000000;font-family:arial;margin:30px;font-size:12px;} 
table{border:0} 
td{line-height:16px;} 
label{cursor:hand;} 
</style> 
</head> 
<body> 
<h1>ico圖標在線轉(zhuǎn)換</h1> 
<form action="?action=make" method="post" enctype=’multipart/form-data’> 
<table> 
    <tr> 
        <td><b>請上傳你要轉(zhuǎn)換的圖片</b><br>支持格式 png,jpg,gif</td> 
    </tr> 
    <tr> 
        <td><input type="file" name="upimage" size="30"></td> 
    </tr> 
    <tr> 
        <td>目標尺寸: 
        <input type="radio" name="size" value="1" id="s1"><label for="s1">16*16</label> 
        <input type="radio" name="size" value="2" id="s2" checked><label for="s2">32*32</label> 
        <input type="radio" name="size" value="3" id="s3"><label for="s3">48*48</label> 
        </td> 
    </tr> 
    <tr> 
        <td align="right"><input type="submit" value="生 成"></td> 
    </tr> 
    <?php 
    if($output){ 
        echo "<tr><td><div style=/"border:1px solid #d8d8b2;background-color:#ffffdd;padding:10px/">".$output."</div></td></tr>"; 
    } 
    ?> 
    <tr> 
        <td><div >powered by <a  >非常愛漫</a> </div></td> 
    </tr> 
</table> 
</form> 
</body> 
</html>

 

以下是phpthumb.ico.php源代碼:
<?php
//////////////////////////////////////////////////////////////
///  phpthumb() by james heinrich <[email protected]>   //
//        available at http://phpthumb.sourceforge.net     ///
//////////////////////////////////////////////////////////////
///                                                         //
// phpthumb.ico.php - .ico output format functions          //
//                                                         ///
//////////////////////////////////////////////////////////////
class phpthumb_ico {
    function phpthumb_ico() {
        return true;
    }
    function gd2icostring(&$gd_image_array) {
        foreach ($gd_image_array as $key => $gd_image) {
            $imagewidths[$key]  = imagesx($gd_image);
            $imageheights[$key] = imagesy($gd_image);
            $bpp[$key]          = imageistruecolor($gd_image) ? 32 : 24;
            $totalcolors[$key]  = imagecolorstotal($gd_image);
            $icxor[$key] = ’’;
            for ($y = $imageheights[$key] - 1; $y >= 0; $y--) {
                for ($x = 0; $x < $imagewidths[$key]; $x++) {
                    $argb = $this->getpixelcolor($gd_image, $x, $y);
                    $a = round(255 * ((127 - $argb[’alpha’]) / 127));
                    $r = $argb[’red’];
                    $g = $argb[’green’];
                    $b = $argb[’blue’];
                    if ($bpp[$key] == 32) {
                        $icxor[$key] .= chr($b).chr($g).chr($r).chr($a);
                    } elseif ($bpp[$key] == 24) {
                        $icxor[$key] .= chr($b).chr($g).chr($r);
                    }
                    if ($a < 128) {
                        @$icandmask[$key][$y] .= ’1’;
                    } else {
                        @$icandmask[$key][$y] .= ’0’;
                    }
                }
                // mask bits are 32-bit aligned per scanline
                while (strlen($icandmask[$key][$y]) % 32) {
                    $icandmask[$key][$y] .= ’0’;
                }
            }
            $icand[$key] = ’’;
            foreach ($icandmask[$key] as $y => $scanlinemaskbits) {
                for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
                    $icand[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, ’0’, str_pad_left)));
                }
            }
        }
        foreach ($gd_image_array as $key => $gd_image) {
            $bisizeimage = $imagewidths[$key] * $imageheights[$key] * ($bpp[$key] / 8);
            // bitmapinfoheader - 40 bytes
            $bitmapinfoheader[$key]  = ’’;
            $bitmapinfoheader[$key] .= "/x28/x00/x00/x00";                              // dword  bisize;
            $bitmapinfoheader[$key] .= $this->littleendian2string($imagewidths[$key], 4);      // long   biwidth;
            // the biheight member specifies the combined
            // height of the xor and and masks.
            $bitmapinfoheader[$key] .= $this->littleendian2string($imageheights[$key] * 2, 4); // long   biheight;
            $bitmapinfoheader[$key] .= "/x01/x00";                                      // word   biplanes;
               $bitmapinfoheader[$key] .= chr($bpp[$key])."/x00";                          // wbitcount;
            $bitmapinfoheader[$key] .= "/x00/x00/x00/x00";                              // dword  bicompression;
            $bitmapinfoheader[$key] .= $this->littleendian2string($bisizeimage, 4);            // dword  bisizeimage;
            $bitmapinfoheader[$key] .= "/x00/x00/x00/x00";                              // long   bixpelspermeter;
            $bitmapinfoheader[$key] .= "/x00/x00/x00/x00";                              // long   biypelspermeter;
            $bitmapinfoheader[$key] .= "/x00/x00/x00/x00";                              // dword  biclrused;
            $bitmapinfoheader[$key] .= "/x00/x00/x00/x00";                              // dword  biclrimportant;
        }
        $icondata  = "/x00/x00";                                      // idreserved;   // reserved (must be 0)
        $icondata .= "/x01/x00";                                      // idtype;       // resource type (1 for icons)
        $icondata .= $this->littleendian2string(count($gd_image_array), 2);  // idcount;      // how many images?
        $dwimageoffset = 6 + (count($gd_image_array) * 16);
        foreach ($gd_image_array as $key => $gd_image) {
            // icondirentry   identries[1]; // an entry for each image (idcount of ’em)
            $icondata .= chr($imagewidths[$key]);                     // bwidth;          // width, in pixels, of the image
            $icondata .= chr($imageheights[$key]);                    // bheight;         // height, in pixels, of the image
            $icondata .= chr($totalcolors[$key]);                     // bcolorcount;     // number of colors in image (0 if >=8bpp)
            $icondata .= "/x00";                                      // breserved;       // reserved ( must be 0)
            $icondata .= "/x01/x00";                                  // wplanes;         // color planes
            $icondata .= chr($bpp[$key])."/x00";                      // wbitcount;       // bits per pixel
            $dwbytesinres = 40 + strlen($icxor[$key]) + strlen($icand[$key]);
            $icondata .= $this->littleendian2string($dwbytesinres, 4);       // dwbytesinres;    // how many bytes in this resource?
            $icondata .= $this->littleendian2string($dwimageoffset, 4);      // dwimageoffset;   // where in the file is this image?
            $dwimageoffset += strlen($bitmapinfoheader[$key]);
            $dwimageoffset += strlen($icxor[$key]);
            $dwimageoffset += strlen($icand[$key]);
        }
        foreach ($gd_image_array as $key => $gd_image) {
            $icondata .= $bitmapinfoheader[$key];
            $icondata .= $icxor[$key];
            $icondata .= $icand[$key];
        }
        return $icondata;
    }
    function littleendian2string($number, $minbytes=1) {
        $intstring = ’’;
        while ($number > 0) {
            $intstring = $intstring.chr($number & 255);
            $number >>= 8;
        }
        return str_pad($intstring, $minbytes, "/x00", str_pad_right);
    }
    function getpixelcolor(&$img, $x, $y) {
        if (!is_resource($img)) {
            return false;
        }
        return @imagecolorsforindex($img, @imagecolorat($img, $x, $y));
    }
}
?>

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 全南县| 柳林县| 水富县| 西乌| 磐安县| 滨海县| 黄冈市| 和顺县| 宝兴县| 伊宁县| 白沙| 岗巴县| 嘉义县| 囊谦县| 昭通市| 舟曲县| 金堂县| 平武县| 三原县| 武安市| 东方市| 鄯善县| 治多县| 油尖旺区| 日喀则市| 沙田区| 湟源县| 南川市| 台安县| 夏河县| 西林县| 阆中市| 大石桥市| 昭通市| 宁陵县| 木兰县| 屏东县| 甘肃省| 金阳县| 乐山市| 海盐县|