ICO图标在线生成,php生成ICO图标在线制作源码
我们做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
微信号:tieniu6636
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· AI与.NET技术实操系列(六):基于图像分类模型对图像进行分类