一键生成各种尺寸Icon的php脚本(实例)
作者:jingxian 发布时间:2024-06-05 09:48:41
标签:一键生成,icon
实例如下:
<?php
/**
* @name thumb 缩略图函数
* @param sting $img_name 图片路径
* @param int $max_width 略图最大宽度
* @param int $max_height 略图最大高度
* @param sting $suffix 略图后缀(如"img_x.jpg"代表小图,"img_m.jpg"代表中图,"img_l.jpg"代表大图)
* @return void
*/
function thumb($img_name,$max_width,$max_height,$path,$new_name)
{
$img_infos = getimagesize($img_name);
$img_height = $img_infos[0];//图片高
$img_width = $img_infos[1]; //图片宽
$img_extension = ''; //图片后缀名
switch($img_infos[2])
{
case 1:
$img_extension = 'gif';
break;
case 2:
$img_extension = 'jpeg';
break;
case 3:
$img_extension = 'png';
break;
default:
$img_extension = 'jpeg';
break;
}
$new_img_size = array();
$new_img_size['width'] = $max_width;
$new_img_size['height'] = $max_height;
$img_func = ''; //函数名称
$img_handle = ''; //图片句柄
$thum_handle = ''; //略图图片句柄
switch($img_extension)
{
case 'jpg':
$img_handle = imagecreatefromjpeg($img_name);
$img_func = 'imagejpeg';
break;
case 'jpeg':
$img_handle = imagecreatefromjpeg($img_name);
$img_func = 'imagejpeg';
break;
case 'png':
$img_handle = imagecreatefrompng($img_name);
imagesavealpha($img_handle, true);
$img_func = 'imagepng';
break;
case 'gif':
$img_handle = imagecreatefromgif($img_name);
$img_func = 'imagegif';
break;
default:
$img_handle = imagecreatefromjpeg($img_name);
$img_func = 'imagejpeg';
break;
}
$quality = 100;//图片质量
if($img_func == 'imagepng')
{
$quality = 9;
}
$thum_handle = imagecreatetruecolor($new_img_size['height'],$new_img_size['width']);
imagealphablending($thum_handle,false);//这里很重要,意思是不合并颜色,直接用$img图像颜色替换,包括透明色;
imagesavealpha($thum_handle,true);//这里很重要,意思是不要丢了$thumb图像的透明色;
if(function_exists('imagecopyresampled'))
{
imagecopyresampled($thum_handle,$img_handle, 0, 0, 0, 0,$new_img_size['height'],$new_img_size['width'],$img_height,$img_width);
}
else
{
imagecopyresized($thum_handle,$img_handle, 0, 0, 0, 0,$new_img_size['height'],$new_img_size['width'],$img_height,$img_width);
}
call_user_func_array($img_func,array($thum_handle,$path.'/'.$new_name,$quality));
imagedestroy($thum_handle);//清除句柄
imagedestroy($img_handle);//清除句柄
}
$IconArray = array
(
"IOS8" => array
(
array("width" => 180, "height"=> 180, "path"=>"ios8", "name"=>"Icon-180.png"),
array("width" => 120, "height"=> 120, "path"=>"ios8", "name"=>"Icon-120.png"),
array("width" => 152, "height"=> 152, "path"=>"ios8", "name"=>"Icon-152.png"),
array("width" => 76, "height"=> 76, "path"=>"ios8", "name"=>"Icon-76.png"),
array("width" => 144, "height"=> 144, "path"=>"ios8", "name"=>"Icon-144.png"),
array("width" => 72, "height"=> 72, "path"=>"ios8", "name"=>"Icon-72.png"),
array("width" => 114, "height"=> 114, "path"=>"ios8", "name"=>"Icon-114.png"),
array("width" => 57, "height"=> 57, "path"=>"ios8", "name"=>"Icon-57.png"),
array("width" => 100, "height"=> 100, "path"=>"ios8", "name"=>"Icon-100.png"),
array("width" => 50, "height"=> 50, "path"=>"ios8", "name"=>"Icon-50.png"),
array("width" => 80, "height"=> 80, "path"=>"ios8", "name"=>"Icon-80.png"),
array("width" => 40, "height"=> 40, "path"=>"ios8", "name"=>"Icon-40.png"),
array("width" => 58, "height"=> 58, "path"=>"ios8", "name"=>"Icon-58.png"),
array("width" => 29, "height"=> 29, "path"=>"ios8", "name"=>"Icon-29.png"),
),
"IOS" => array
(
array("width" => 180, "height"=> 180, "path"=>"ios", "name"=>"Icon-60@3x.png"),
array("width" => 120, "height"=> 120, "path"=>"ios", "name"=>"Icon-60@2x.png"),
array("width" => 152, "height"=> 152, "path"=>"ios", "name"=>"Icon-76@2x.png"),
array("width" => 76, "height"=> 76, "path"=>"ios", "name"=>"Icon-76.png"),
array("width" => 144, "height"=> 144, "path"=>"ios", "name"=>"Icon-72@2x.png"),
array("width" => 72, "height"=> 72, "path"=>"ios", "name"=>"Icon-72.png"),
array("width" => 114, "height"=> 114, "path"=>"ios", "name"=>"Icon-57@2x.png"),
array("width" => 57, "height"=> 57, "path"=>"ios", "name"=>"Icon-57.png"),
array("width" => 100, "height"=> 100, "path"=>"ios", "name"=>"Icon-50@2x.png"),
array("width" => 50, "height"=> 50, "path"=>"ios", "name"=>"Icon-50.png"),
array("width" => 80, "height"=> 80, "path"=>"ios", "name"=>"Icon-40@2x.png"),
array("width" => 40, "height"=> 40, "path"=>"ios", "name"=>"Icon-40.png"),
array("width" => 58, "height"=> 58, "path"=>"ios", "name"=>"Icon-29@2x.png"),
array("width" => 29, "height"=> 29, "path"=>"ios", "name"=>"Icon-29.png"),
)
,
"ANDROID" => array
(
array("width" => 144, "height" => 144, "path" => "android/drawable", "name"=>"icon.png"),
array("width" => 144, "height" => 144, "path" => "android/drawable-xhdpi", "name"=>"icon.png"),
array("width" => 72, "height" => 72, "path" => "android/drawable-hdpi", "name"=>"icon.png"),
array("width" => 48, "height" => 48, "path" => "android/drawable-mdpi", "name"=>"icon.png"),
array("width" => 32, "height" => 32, "path" => "android/drawable-ldpi", "name"=>"icon.png")
)
);
foreach ($IconArray["IOS8"] as $key => $IconType)
{
thumb("icon.png",$IconType['width'],$IconType['height'],$IconType['path'],$IconType['name']);
}
foreach ($IconArray["IOS"] as $key => $IconType)
{
thumb("icon.png",$IconType['width'],$IconType['height'],$IconType['path'],$IconType['name']);
}
foreach ($IconArray["ANDROID"] as $key => $IconType)
{
thumb("icon.png",$IconType['width'],$IconType['height'],$IconType['path'],$IconType['name']);
}
?>


猜你喜欢
- python中ftplib模块支持ftp操作,主要使用FTP类。本文使用ftp操作进行连接FTP服务器、获取当前目录文件清单、上传文件等操作
- 1. 问题重现(回显)类似的问题还有很多2. 解决方法:将下图 箭头指的两个项 取消勾选 就好了下载 vs code 插
- 一、把MySql.Data.dll放到BIN目录下。 二、这是aspx.cs的全部源码,修改参数直接运行即可! &nbs
- 大家都在关注视觉的盛宴,西方的美学;今天就分享下,中国最为古老的美,也是身边随处可见的美学–中国汉字书法之美;古文者,仓颉做造也。仰观奎星园
- 一、项目创建 1.1 创建项目在IDEA中,File--New--Project--Spring Initializer名称为sp
- 前言ThinkPHP,是为了简化企业级应用开发和敏捷WEB应用开发而诞生的开源轻量级PHP框架。随着框架代码量的增加,一些潜在的威胁也逐渐暴
- static function convert($size) { &
- 一、前言一个Sql Server 开发智能提示插件,方便查询表结果,避免了开发人员一个个敲查询语句、执行语句等,一起来看看吧。SQL Pro
- MVC和MTV框架 MVC Web服务器开发领域里著名的MVC模式,所谓MVC就是把Web应用分为模型(M),控制器(C)和视图(V)三层,
- Python实现文件的全备份和差异备份之前有写利用md5方式来做差异备份,但是这种md5方式来写存在以下问题:md5sum获取有些软连接的M
- 一、问题描述给定两个字符串,求解这两个字符串的最长公共子序列(Longest Common Sequence)。比如字符串1:BDCABA;
- #!/usr/bin/env python# -*- coding:utf-8 -*-# *************************
- 如果不清楚字符串的编码格式的话,就可以将这段字符这样检查:$encode = mb_detect_encoding($string, arr
- function createobj() { if (window.ActiveXObject)&n
- 今天在一个QQ群中看到有人在问一个进度条的实现方式,当时因为工作时间,需求相对也比较紧,只是简单的说了一下可以通过CSS的边框属性和背景属性
- 相信大家一定碰到过,打开某个网页,却显示一堆像乱码,如"бЇЯАзЪСЯ"、"�????????"?
- 表单外观的美化很多时候,我们仅仅为了实现数据采集这个功能来使用表单,常看到的表单都是“千人一面”、毫无
- 目录1. 正则表达式_匹配单个字符2. 正则表达式_匹配多个字符3. 正则表达式_匹配分组小提示:4. 小练习答案:总结1. 正则表达式_匹
- 在python中,“np”一般是指“numpy”库,是第三方库“numpy”的别名。方法:利用命令“import numpy as np”将
- 概述最近买了台服务器,准备搭建个人博客,来持续更新自己的博客,环境服务器操作系统:CentOS 7.0博客部署服务器:Apache后台语言: