我们做web系统的时候,每个浏览器的tab这里都会有一个图标,这个图标叫favicon图标,favicon.ico文件放在系统的根目录

如果程序员没有ICO制作工具,那么要如何生成图标呢?可以用程序来实现生成啊!也可以把图标裁剪好,选择在线生成,在线生成测试地址:www.vsoyo.com/ico

下面和大家一起探讨下,php生成ICO图标在线制作源码,很简单的原理,请看如下代码

下面是ICO图标在线生成的主要代码

<?php
if(!function_exists("generate_favicon")){
function generate_favicon(){
// Create favicon.
$postvars = array(
"image" => trim($_FILES["image"]["name"]),
"image_tmp" => $_FILES["image"]["tmp_name"],
"image_size" => (int)$_FILES["image"]["size"],
"image_dimensions" => (int)$_POST["image_dimensions"]); // Provide valid extensions and max file size
$valid_exts = array("jpg","jpeg","gif","png");
$max_file_size = 179200; // 175kb $filenameParts = explode(".",$postvars["image"]);
$ext = strtolower(end($filenameParts));
$directory = "./favicon/"; // Directory to save favicons. Include trailing slash.
$rand = rand(1000,9999);
$filename = $rand.$postvars["image"]; // Check not larger than max size.
if($postvars["image_size"] <= $max_file_size){
// Check is valid extension.
if(in_array($ext,$valid_exts)){
if($ext == "jpg" || $ext == "jpeg"){
$image = imagecreatefromjpeg($postvars["image_tmp"]);
}
else if($ext == "gif"){
$image = imagecreatefromgif($postvars["image_tmp"]);
}
else if($ext == "png"){
$image = imagecreatefrompng($postvars["image_tmp"]);
}
if($image){
list($width,$height) = getimagesize($postvars["image_tmp"]);
$newwidth = $postvars["image_dimensions"];
$newheight = $postvars["image_dimensions"];
$tmp = imagecreatetruecolor($newwidth,$newheight); // Copy the image to one with the new width and height.
imagecopyresampled($tmp,$image,0,0,0,0,$newwidth,$newheight,$width,$height); // Create image file with 100% quality.
if(is_dir($directory)){
if(is_writable($directory)){
imagejpeg($tmp,$directory.$filename,100) or die('Could not make image file');
if(file_exists($directory.$filename)){
// Image created, now rename it to its
$ext_pos = strpos($rand.$postvars["image"],"." . $ext);
$strip_ext = substr($rand.$postvars["image"],0,$ext_pos);
// Rename image to .ico file
rename($directory.$filename,$directory.$strip_ext.".ico");
return '<strong>图标预览:</strong><br/>
<img src="'.$directory.$strip_ext.'.ico" border="0" title="Favicon 完毕预览" style="padding: 4px 0px 4px 0px;background-color:#e0e0e0" /><br/>
Favicon/ICO图标制作完毕: <a href="'.$directory.$strip_ext.'.ico" target="_blank" name="右键另存为下载!">点击/右键另存下载,后重命名为"favicon.ico"</a>';
} else {
"File was not created.";
}
} else {
return 'The directory: "'.$directory.'" is not writable.';
}
} else {
return 'The directory: "'.$directory.'" is not valid.';
} imagedestroy($image);
imagedestroy($tmp);
} else {
return "Could not create image file.";
}
} else {
return "图标过大,不能超过175KB";
}
} else {
return "图片格式只能是后面几种 (jpg, jpeg, gif, png).";
}
}
} ?>

需要进一步技术交流的朋友 ,请加我微信吧:15889726201

ICO图标在线生成,php生成ICO图标在线制作源码的更多相关文章

  1. Linq生成操作之DefautIfEmpty,Empty,Range,Repeat源码分析

    Linq生成操作之DefautIfEmpty,Empty,Range,Repeat源码分析 Linq的四种生成运算 DefautIfEmpty,Empty,Range,Repeat 也就是给我们初始化 ...

  2. C#使用Xamarin开发可移植移动应用进阶篇(8.打包生成安卓APK并精简大小),附源码

    前言 系列目录 C#使用Xamarin开发可移植移动应用目录 源码地址:https://github.com/l2999019/DemoApp 可以Star一下,随意 - - 说点什么.. 嗯,前面讲 ...

  3. 一个web图片热点生成工具(winform开发) 附源码

    给图片加热点是web开发中经常用到的一个功能.这方面的工具也不少. 为了更好的满足自己的需求,写了一个winform程序. 可以方便的给图片加热点,更方便灵活! 源码下载 http://downloa ...

  4. JAVA WEB项目中生成验证码及验证实例(附源码及目录结构)

    [我是一个初学者,自己总结和网上搜索资料,代码是自己敲了一遍,亲测有效,现将所有的目录结构和代码贴出来分享给像我一样的初学者] 作用 验证码为全自动区分计算机和人类的图灵测试的缩写,是一种区分用户是计 ...

  5. MYSQL在线注释文档--- 在gdb中显示源码(gdbtui使用方法)----赖明星的个人博客

    http://mingxinglai.com/cn/2013/07/gdbtui/ MySQL源码注释与类图 http://mingxinglai.com/cn/2015/08/mysql-annot ...

  6. uSurvival 1.41多人在线生存逃杀吃鸡类游戏源码

    uSurvival - the new Multiplayer Survival Asset from the creator of uMMORPG. Features:* Kill Zombies ...

  7. Mybatis Generator的model生成中文注释,支持oracle和mysql(通过修改源码的方式来实现)

    在看本篇之前,最好先看一下上一篇通过实现CommentGenerator接口的方法来实现中文注释的例子,因为很多操作和上一篇基本是一致的,所以本篇可能不那么详细. 首先说一下上篇通过实现Comment ...

  8. favicon.ico显示,favicon显示,favicon图标显示

    favicon.ico显示,favicon显示,favicon图标显示 >>>>>>>>>>>>>>>> ...

  9. VS2013 更改MFC标题栏图标和生成的执行文件图标

    创建一个新工程,可以什么都不加.打开.rc,  创建或打开Icon资源(以下都以Icon为例).     单击工程窗口的资源视图标签,选中资源ID为IDR_MAINFRAME图标资源,然后按Delet ...

随机推荐

  1. loadrunner--分析图合并

    一.分析图合并原理 选择view->merge graphs,弹出如图1所示对话框 图1(设置合并图) 1.选择要合并的图.选择一个要与当前活动图合并的图,注意这里只能选择X轴度量单位相同的图. ...

  2. P2P网贷-借款与发标

     P2P网贷-借款与发标 关于借款,我想说,需要资金的人真的很多.贷款利率不太高的情况下,借款客户相对而言还是比较好开发的, 比较难的是,确保客户能按时还款.目前,信用还是比较混乱的. 借款来源,客户 ...

  3. WebClient 请求返回的是Gbk编码解决方案

    WebClient client = new WebClient();                client.Headers.Clear();                client.Hea ...

  4. Searching with regular sentences will only get you so far – if you need to find something a bit tricky turn to these advanced yet simple methods--转

    原文地址:http://www.theguardian.com/technology/2016/jan/15/how-to-use-search-like-a-pro-10-tips-and-tric ...

  5. 2、应用程序及驱动-poll和select使用说明

    1.poll机制(如果中断机制出问题了,poll机制是对中断机制的补充,比如等一个小孩,如果小孩生病了,因此隔一段时间应该去找他) poll机制就是给定一段时间,在这一段时间内程序处于睡眠状态一直等待 ...

  6. Oracle以系统管理员的方式登录失败

    解决方法: 因为SYS是在数据库之外的超级管理员,所以我们在登录的时候输入sys后在输入命令:password as sysdba 就可以!例如:输入口令: m1234 as sysdba 参考文章 ...

  7. IQMath是什么 浮点转定点运算,dsp

    [转帖注明出处:blog.csdn.net/lanmanck] 网上搜了一下没发现非常合适的,特写出来与大家分享. 大家都知道嵌入式系统里带浮点运算指令的CPU都比較少,TI的DSP也是定点的廉价. ...

  8. 结合Wireshark捕获分组深入理解TCP/IP协议之IP协议

    摘要:     本文简单介绍了网络层理论知识,详细讲解了IP数据报各个字段,并从Wireshark俘获分组中选取IP数据报进行分析,也阐述了分组和分片的区别.   一.IPv4数据报     网络层是 ...

  9. aspcms产品详情页调取相关产品

    产品详情页调用相关产品最常见的应用就是装饰公司网站,设计师页面要求调取设计师做过的案例.aspcms本身有这个功能,但不能完全符合要求,看代码 {aspcms:content sort={aspcms ...

  10. [Pug] Template Engine -- Jade/ Pug

    Looking at the follow code: .wrapper - const upName = name && name.toUpperCase(); h2 | Hello ...