首页 后端开发 php教程 一键生成各种尺寸Icon的php脚本

一键生成各种尺寸Icon的php脚本

Aug 08, 2016 am 09:23 AM
gt height name quot width

<?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 = &#39;&#39;;		//图片后缀名

	switch($img_infos[2])
	{
		case 1:
			$img_extension = &#39;gif&#39;;
			break;
		case 2:
			$img_extension = &#39;jpeg&#39;;
			break;
		case 3:
			$img_extension = &#39;png&#39;;
			break;
		default:
			$img_extension = &#39;jpeg&#39;;
			break;
	}

	$new_img_size = array();
	$new_img_size[&#39;width&#39;] = $max_width;
	$new_img_size[&#39;height&#39;] = $max_height;
	
	$img_func = &#39;&#39;;		//函数名称
	$img_handle = &#39;&#39;;	//图片句柄
	$thum_handle = &#39;&#39;;	//略图图片句柄

	switch($img_extension)
	{
		case &#39;jpg&#39;:
			$img_handle = imagecreatefromjpeg($img_name);
			$img_func = &#39;imagejpeg&#39;;
			break;
		case &#39;jpeg&#39;:
			$img_handle = imagecreatefromjpeg($img_name);
			$img_func = &#39;imagejpeg&#39;;
			break;
		case &#39;png&#39;:
			$img_handle = imagecreatefrompng($img_name);
			imagesavealpha($img_handle, true);
			$img_func = &#39;imagepng&#39;;
			break;
		case &#39;gif&#39;:
		 	$img_handle = imagecreatefromgif($img_name);
			$img_func = &#39;imagegif&#39;;
			break;
		default:
			$img_handle = imagecreatefromjpeg($img_name);
			$img_func = &#39;imagejpeg&#39;;
			break;
	}

	$quality = 100;//图片质量
	if($img_func == &#39;imagepng&#39;)
	{
		$quality = 9;
	} 

	$thum_handle = imagecreatetruecolor($new_img_size[&#39;height&#39;],$new_img_size[&#39;width&#39;]);
	imagealphablending($thum_handle,false);//这里很重要,意思是不合并颜色,直接用$img图像颜色替换,包括透明色;
    imagesavealpha($thum_handle,true);//这里很重要,意思是不要丢了$thumb图像的透明色;

	if(function_exists(&#39;imagecopyresampled&#39;))
	{
		imagecopyresampled($thum_handle,$img_handle, 0, 0, 0, 0,$new_img_size[&#39;height&#39;],$new_img_size[&#39;width&#39;],$img_height,$img_width);
	} 
	else 
	{
		imagecopyresized($thum_handle,$img_handle, 0, 0, 0, 0,$new_img_size[&#39;height&#39;],$new_img_size[&#39;width&#39;],$img_height,$img_width);
	}

    call_user_func_array($img_func,array($thum_handle,$path.&#39;/&#39;.$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']);
}

?>
登录后复制

使用方法:  php IconMaster.php 

以上就介绍了 一键生成各种尺寸Icon的php脚本,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
2 周前 By 尊渡假赌尊渡假赌尊渡假赌
仓库:如何复兴队友
4 周前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

华为GT3 Pro和GT4的差异是什么? 华为GT3 Pro和GT4的差异是什么? Dec 29, 2023 pm 02:27 PM

许多用户在选择智能手表的时候都会选择的华为的品牌,其中华为GT3pro和GT4都是非常热门的选择,不少用户都很好奇华为GT3pro和GT4有什么区别,下面就就给大家介绍一下二者。华为GT3pro和GT4有什么区别一、外观GT4:46mm和41mm,材质是玻璃表镜+不锈钢机身+高分纤维后壳。GT3pro:46.6mm和42.9mm,材质是蓝宝石玻璃表镜+钛金属机身/陶瓷机身+陶瓷后壳二、健康GT4:采用最新的华为Truseen5.5+算法,结果会更加的精准。GT3pro:多了ECG心电图和血管及安

修复:截图工具在 Windows 11 中不起作用 修复:截图工具在 Windows 11 中不起作用 Aug 24, 2023 am 09:48 AM

为什么截图工具在Windows11上不起作用了解问题的根本原因有助于找到正确的解决方案。以下是截图工具可能无法正常工作的主要原因:对焦助手已打开:这可以防止截图工具打开。应用程序损坏:如果截图工具在启动时崩溃,则可能已损坏。过时的图形驱动程序:不兼容的驱动程序可能会干扰截图工具。来自其他应用程序的干扰:其他正在运行的应用程序可能与截图工具冲突。证书已过期:升级过程中的错误可能会导致此issu简单的解决方案这些适合大多数用户,不需要任何特殊的技术知识。1.更新窗口和Microsoft应用商店应用程

html的width是什么意思 html的width是什么意思 Jun 03, 2021 pm 02:15 PM

在html5中,width的意思是宽度,width属性定义元素内容区的宽度,在内容区外面可以增加内边距、边框和外边距,只需要给元素设置“元素{width:数值}”即可。

如何修复无法连接到iPhone上的App Store错误 如何修复无法连接到iPhone上的App Store错误 Jul 29, 2023 am 08:22 AM

第1部分:初始故障排除步骤检查苹果的系统状态:在深入研究复杂的解决方案之前,让我们从基础知识开始。问题可能不在于您的设备;苹果的服务器可能会关闭。访问Apple的系统状态页面,查看AppStore是否正常工作。如果有问题,您所能做的就是等待Apple修复它。检查您的互联网连接:确保您拥有稳定的互联网连接,因为“无法连接到AppStore”问题有时可归因于连接不良。尝试在Wi-Fi和移动数据之间切换或重置网络设置(“常规”>“重置”>“重置网络设置”>设置)。更新您的iOS版本:

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

CSS 维度属性详解:height 和 width CSS 维度属性详解:height 和 width Oct 21, 2023 pm 12:42 PM

CSS维度属性详解:height和width在前端开发中,CSS是一种强大的样式定义语言。其中,height和width是两个最基本的维度属性,用于定义元素的高度和宽度。本文将对这两个属性进行详细解析,并提供具体的代码示例。一、height属性height属性用于定义元素的高度。可以使用像素(pixel)、百分比(percentage)或者

watch4pro好还是gt好 watch4pro好还是gt好 Sep 26, 2023 pm 02:45 PM

watch4pro和gt各自具有不用的特点和适用场景,如果注重功能的全面性、高性能和时尚外观,同时愿意承担较高的价格,那么Watch 4 Pro可能更适合。如果对功能要求不高,更注重电池续航和价格的合理性,那么GT系列可能更适合。最终的选择应根据个人需求、预算和喜好来决定,建议在购买前仔细考虑自己的需求,并参考各种产品的评测和比较,以做出更明智的选择。

css表示width值有哪些方法 css表示width值有哪些方法 Nov 13, 2023 pm 05:47 PM

方法有像素值、百分比、em单位、rem单位、vw/vh单位、auto、fit-content、min-content、max-content。详细介绍:1、像素值(px):像素值是固定的,不论屏幕分辨率如何变化,它的宽度都是不变的。例如:width: 300px;2、百分比(%):百分比宽度是相对于父元素的宽度的。例如:width: 50%;3、em单位等等。

See all articles