仓酷云

标题: PHP网页编程之在线生成favicon.ico或ico图标源码 [打印本页]

作者: 飘飘悠悠    时间: 2015-2-4 00:08
标题: PHP网页编程之在线生成favicon.ico或ico图标源码
即使你理解不了PHP,但是也必须先跟它混个脸熟,看,一遍遍的看,看的同时一边琢磨,一边按照它所教的打代码,即使你搞不清楚那些代码到底是干嘛的,但是起码你应该找找感觉。在线|favicon   php在线生成ico文件源代码.

favicon图标引见

favicon.ico普通用于作为缩略的网站标记,它显示位于阅读器的地址栏或在标签上,用于显示网站的logo,如图红圈的地位, 今朝次要的阅读器都撑持favicon.ico图标.

以下是index.php源代码
<?PHP  
&#36;output = "";  
if(isset(&#36;_GET[’action’])&&&#36;_GET[’action’] == ’make’){  
    if(isset(&#36;_FILES[’upimage’][’tmp_name’]) && &#36;_FILES[’upimage’][’tmp_name’] && is_uploaded_file(&#36;_FILES[’upimage’][’tmp_name’])){  
        if(&#36;_FILES[’upimage’][’type’]>210000){  
            echo "你上传的文件体积超越了限制 最大不克不及超越200K";  
            exit();  
        }  
        &#36;fileext = array("image/pjpeg","image/gif","image/x-png");  
        if(!in_array(&#36;_FILES[’upimage’][’type’],&#36;fileext)){  
            echo "你上传的文件格局不准确 仅撑持 jpg,gif,png";  
            exit();  
        }  
        if(&#36;im = @imagecreatefrompng(&#36;_FILES[’upimage’][’tmp_name’]) or &#36;im = @imagecreatefromgif(&#36;_FILES[’upimage’][’tmp_name’]) or &#36;im = @imagecreatefromjpeg(&#36;_FILES[’upimage’][’tmp_name’])){  
            &#36;imginfo = @getimagesize(&#36;_FILES[’upimage’][’tmp_name’]);  
            if(!is_array(&#36;imginfo)){  
                echo "图形格局毛病!";  
            }  
            switch(&#36;_POST[’size’]){  
                case 1;  
                    &#36;resize_im = @imagecreatetruecolor(16,16);  
                    &#36;size = 16;  
                    break;  
                case 2;  
                    &#36;resize_im = @imagecreatetruecolor(32,32);  
                    &#36;size = 32;  
                    break;  
                case 3;  
                    &#36;resize_im = @imagecreatetruecolor(48,48);  
                    &#36;size = 48;  
                    break;  
                default;  
                    &#36;resize_im = @imagecreatetruecolor(32,32);  
                    &#36;size = 32;  
                    break;  
            }  
            imagecopyresampled(&#36;resize_im,&#36;im,0,0,0,0,&#36;size,&#36;size,&#36;imginfo[0],&#36;imginfo[1]);  
            include "phpthumb.ico.php";  
            &#36;icon = new phpthumb_ico();  
            &#36;gd_image_array = array(&#36;resize_im);  
            &#36;icon_data = &#36;icon->GD2ICOstring(&#36;gd_image_array);  
            &#36;filename = "temp/".date("Ymdhis").rand(1,1000).".ico";  
            if(file_put_contents(&#36;filename, &#36;icon_data)){  
                &#36;output = "生成胜利!请点右键->另存为 保留到当地<br><a href=\"".&#36;filename."\" target=\"_blank\">点击下载</a>";  
            }  
        }else{  
            echo "生成毛病请重试!";  
        }  
    }      
}  
?>  
<html>  
<head>  
<title>ICO图标在线转换</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图标在线转换</h1>  
<form action="?action=make" method="post" enctype=’multipart/form-data’>  
<table>  
    <tr>  
        <td><b>请上传你要转换的图片</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(&#36;output){  
        echo "<tr><td><div style=\"border:1px solid #D8D8B2;background-color:#FFFFDD;padding:10px\">".&#36;output."</div></td></tr>";  
    }  
    ?>  
    <tr>  
        <td><div style="color:#cccccc;font-size:11px;">Powered by <a href="http://veryim.com" style="color:#cccccc">十分爱漫</a> </div></td>  
    </tr>  
</table>  
</form>  
</body>  
</html>


  以下是phpthumb.ico.php源代码:
<?php
//////////////////////////////////////////////////////////////
///  phpThumb() by James Heinrich <info@silisoftware.com>   //
//        available at http://phpthumb.sourceforge.net     ///
//////////////////////////////////////////////////////////////
///                                                         //
// phpthumb.ico.php - .ICO output format functions          //
//                                                         ///
//////////////////////////////////////////////////////////////
class phpthumb_ico {
    function phpthumb_ico() {
        return true;
    }
    function GD2ICOstring(&&#36;gd_image_array) {
        foreach (&#36;gd_image_array as &#36;key => &#36;gd_image) {
            &#36;ImageWidths[&#36;key]  = ImageSX(&#36;gd_image);
            &#36;ImageHeights[&#36;key] = ImageSY(&#36;gd_image);
            &#36;bpp[&#36;key]          = ImageIsTrueColor(&#36;gd_image) ? 32 : 24;
            &#36;totalcolors[&#36;key]  = ImageColorsTotal(&#36;gd_image);
            &#36;icXOR[&#36;key] = ’’;
            for (&#36;y = &#36;ImageHeights[&#36;key] - 1; &#36;y >= 0; &#36;y--) {
                for (&#36;x = 0; &#36;x < &#36;ImageWidths[&#36;key]; &#36;x++) {
                    &#36;argb = &#36;this->GetPixelColor(&#36;gd_image, &#36;x, &#36;y);
                    &#36;a = round(255 * ((127 - &#36;argb[’alpha’]) / 127));
                    &#36;r = &#36;argb[’red’];
                    &#36;g = &#36;argb[’green’];
                    &#36;b = &#36;argb[’blue’];
                    if (&#36;bpp[&#36;key] == 32) {
                        &#36;icXOR[&#36;key] .= chr(&#36;b).chr(&#36;g).chr(&#36;r).chr(&#36;a);
                    } elseif (&#36;bpp[&#36;key] == 24) {
                        &#36;icXOR[&#36;key] .= chr(&#36;b).chr(&#36;g).chr(&#36;r);
                    }
                    if (&#36;a < 128) {
                        @&#36;icANDmask[&#36;key][&#36;y] .= ’1’;
                    } else {
                        @&#36;icANDmask[&#36;key][&#36;y] .= ’0’;
                    }
                }
                // mask bits are 32-bit aligned per scanline
                while (strlen(&#36;icANDmask[&#36;key][&#36;y]) % 32) {
                    &#36;icANDmask[&#36;key][&#36;y] .= ’0’;
                }
            }
            &#36;icAND[&#36;key] = ’’;
            foreach (&#36;icANDmask[&#36;key] as &#36;y => &#36;scanlinemaskbits) {
                for (&#36;i = 0; &#36;i < strlen(&#36;scanlinemaskbits); &#36;i += 8) {
                    &#36;icAND[&#36;key] .= chr(bindec(str_pad(substr(&#36;scanlinemaskbits, &#36;i, 8), 8, ’0’, STR_PAD_LEFT)));
                }
            }
        }
        foreach (&#36;gd_image_array as &#36;key => &#36;gd_image) {
            &#36;biSizeImage = &#36;ImageWidths[&#36;key] * &#36;ImageHeights[&#36;key] * (&#36;bpp[&#36;key] / 8);
            // BITMAPINFOHEADER - 40 bytes
            &#36;BitmapInfoHeader[&#36;key]  = ’’;
            &#36;BitmapInfoHeader[&#36;key] .= "\x28\x00\x00\x00";                              // DWORD  biSize;
            &#36;BitmapInfoHeader[&#36;key] .= &#36;this->LittleEndian2String(&#36;ImageWidths[&#36;key], 4);      // LONG   biWidth;
            // The biHeight member specifies the combined
            // height of the XOR and AND masks.
            &#36;BitmapInfoHeader[&#36;key] .= &#36;this->LittleEndian2String(&#36;ImageHeights[&#36;key] * 2, 4); // LONG   biHeight;
            &#36;BitmapInfoHeader[&#36;key] .= "\x01\x00";                                      // WORD   biPlanes;
               &#36;BitmapInfoHeader[&#36;key] .= chr(&#36;bpp[&#36;key])."\x00";                          // wBitCount;
            &#36;BitmapInfoHeader[&#36;key] .= "\x00\x00\x00\x00";                              // DWORD  biCompression;
            &#36;BitmapInfoHeader[&#36;key] .= &#36;this->LittleEndian2String(&#36;biSizeImage, 4);            // DWORD  biSizeImage;
            &#36;BitmapInfoHeader[&#36;key] .= "\x00\x00\x00\x00";                              // LONG   biXPelsPerMeter;
            &#36;BitmapInfoHeader[&#36;key] .= "\x00\x00\x00\x00";                              // LONG   biYPelsPerMeter;
            &#36;BitmapInfoHeader[&#36;key] .= "\x00\x00\x00\x00";                              // DWORD  biClrUsed;
            &#36;BitmapInfoHeader[&#36;key] .= "\x00\x00\x00\x00";                              // DWORD  biClrImportant;
        }
        &#36;icondata  = "\x00\x00";                                      // idReserved;   // Reserved (must be 0)
        &#36;icondata .= "\x01\x00";                                      // idType;       // Resource Type (1 for icons)
        &#36;icondata .= &#36;this->LittleEndian2String(count(&#36;gd_image_array), 2);  // idCount;      // How many images?
        &#36;dwImageOffset = 6 + (count(&#36;gd_image_array) * 16);
        foreach (&#36;gd_image_array as &#36;key => &#36;gd_image) {
            // ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of ’em)
            &#36;icondata .= chr(&#36;ImageWidths[&#36;key]);                     // bWidth;          // Width, in pixels, of the image
            &#36;icondata .= chr(&#36;ImageHeights[&#36;key]);                    // bHeight;         // Height, in pixels, of the image
            &#36;icondata .= chr(&#36;totalcolors[&#36;key]);                     // bColorCount;     // Number of colors in image (0 if >=8bpp)
            &#36;icondata .= "\x00";                                      // bReserved;       // Reserved ( must be 0)
            &#36;icondata .= "\x01\x00";                                  // wPlanes;         // Color Planes
            &#36;icondata .= chr(&#36;bpp[&#36;key])."\x00";                      // wBitCount;       // Bits per pixel
            &#36;dwBytesInRes = 40 + strlen(&#36;icXOR[&#36;key]) + strlen(&#36;icAND[&#36;key]);
            &#36;icondata .= &#36;this->LittleEndian2String(&#36;dwBytesInRes, 4);       // dwBytesInRes;    // How many bytes in this resource?
            &#36;icondata .= &#36;this->LittleEndian2String(&#36;dwImageOffset, 4);      // dwImageOffset;   // Where in the file is this image?
            &#36;dwImageOffset += strlen(&#36;BitmapInfoHeader[&#36;key]);
            &#36;dwImageOffset += strlen(&#36;icXOR[&#36;key]);
            &#36;dwImageOffset += strlen(&#36;icAND[&#36;key]);
        }
        foreach (&#36;gd_image_array as &#36;key => &#36;gd_image) {
            &#36;icondata .= &#36;BitmapInfoHeader[&#36;key];
            &#36;icondata .= &#36;icXOR[&#36;key];
            &#36;icondata .= &#36;icAND[&#36;key];
        }
        return &#36;icondata;
    }
    function LittleEndian2String(&#36;number, &#36;minbytes=1) {
        &#36;intstring = ’’;
        while (&#36;number > 0) {
            &#36;intstring = &#36;intstring.chr(&#36;number & 255);
            &#36;number >>= 8;
        }
        return str_pad(&#36;intstring, &#36;minbytes, "\x00", STR_PAD_RIGHT);
    }
    function GetPixelColor(&&#36;img, &#36;x, &#36;y) {
        if (!is_resource(&#36;img)) {
            return false;
        }
        return @ImageColorsForIndex(&#36;img, @ImageColorAt(&#36;img, &#36;x, &#36;y));
    }
}
?>
学习数据库了,MYSQL可算是PHP的黄金搭档了,不过,虽然话是这么说,你也可能恨不得把MYSQL给生吞活剥了,因为这一行一列的东东简直让自己头晕目眩。
作者: 兰色精灵    时间: 2015-2-4 09:24
建议加几个专业的phper的群,当然啦需要说话的人多,一处一点问题能有人回答你的,当然啦要让人回答你的问题,平时就得躲在里面聊天,大家混熟啦,愿意回答你问题的人自然就多啦。
作者: 谁可相欹    时间: 2015-2-4 21:03
使用zendstdio 写代码的的时候,把tab 的缩进设置成4个空格是很有必要的
作者: 小妖女    时间: 2015-2-10 10:30
这些中手常用的知识,当你把我说的这些关键字都可以熟练运用的时候,你可以选择自己
作者: 冷月葬花魂    时间: 2015-2-11 05:05
Apache不是非得用80或者8080端口的,我刚开始安得时候就是80端口老占用,就用了个 81端口,结果照常,就是输localhost的时候,应该输入为 localhost:81
作者: 莫相离    时间: 2015-2-16 01:24
对于懒惰的朋友,我推荐php的集成环境xampp或者是wamp。这两个软件安装方便,使用简单。但是我还是强烈建议自己动手搭建开发环境。
作者: 金色的骷髅    时间: 2015-3-4 21:22
我学习了一段时间后,我发现效果并不好(估计是我自身的问题)。因为一个人的精力总是有限的,同时学习这么多,会导致每个的学习时间都得不到保证。
作者: 柔情似水    时间: 2015-3-11 21:05
其实也不算什么什么心得,在各位大侠算是小巫见大巫了吧,望大家不要见笑,若其中有错误的地方请各位大虾斧正。
作者: 因胸联盟    时间: 2015-3-17 04:07
说php的话,首先得提一下数组,开始的时候我是最烦数组的,总是被弄的晕头转向,不过后来呢,我觉得数组里php里最强大的存储方法,所以建议新手们要学好数组。
作者: 乐观    时间: 2015-3-20 19:34
学好程序语言,多些才是王道,写两个小时代码的作用绝对超过看一天书,这个我是深有体会(顺便还能练打字速度)。
作者: 飘飘悠悠    时间: 2015-3-22 22:09
说php的话,首先得提一下数组,开始的时候我是最烦数组的,总是被弄的晕头转向,不过后来呢,我觉得数组里php里最强大的存储方法,所以建议新手们要学好数组。
作者: 不帅    时间: 2015-3-24 22:35
实践是检验自己会不会的真理。
作者: 精灵巫婆    时间: 2015-3-26 23:38
装在C盘下面可以利用windows的ghost功能可以还原回来(顺便当做是重转啦),当然啦我的编译目录要放在别的盘下,不然自己的劳动成果就悲剧啦。
作者: 蒙在股里    时间: 2015-3-27 11:10
使用zendstdio 写代码的的时候,把tab 的缩进设置成4个空格是很有必要的
作者: admin    时间: 2015-4-1 14:12
在我安装pear包的时候老是提示,缺少某某文件,才发现 那群extension 的排列是应该有一点的顺序,而我安装的版本的排序不是正常的排序。没办法我只好把那群冒号加了上去,只留下我需要使用的扩展。
作者: 若相依    时间: 2015-4-6 13:07
不禁又想起那些说php是草根语言的人,为什么认得差距这么大呢。
作者: 飘灵儿    时间: 2015-4-13 17:26
写的比较杂,因为我也是个新手,不当至于大家多多指正。
作者: 透明    时间: 2015-4-16 19:29
做为1门年轻的语言,php一直很努力。
作者: 活着的死人    时间: 2015-4-26 09:11
真正的方向了,如果将来要去开发团队,你一定要学好smarty ,phplib这样的模板引擎,
作者: 山那边是海    时间: 2015-4-26 11:15
本文当是我的笔记啦,遇到的问题随时填充
作者: 若天明    时间: 2015-4-28 20:20
要进行开发,搭建环境是首先需要做的事,windows下面我习惯把环境那个安装在C盘下面,因为我配的环境经常出现诡异事件,什么事都没做环境有的时候就不能用啦。




欢迎光临 仓酷云 (http://ckuyun.com/) Powered by Discuz! X3.2