介绍
这篇文章将为大家详细讲解有关利用PHP怎么对png图像进行缩放,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
具体实现方法如下:
function smart_resize_image(,文件,美元width 美元;=,0,,height 美元;=,0,,proportional 美元;=,假,,output 美元;=,& # 39;文件# 39;,,delete_original 美元;=,真的,,use_linux_commands 美元;=,false ) { ,,,if (=, height 美元;& lt; 0,,,, width 美元;& lt;=, 0,), { ,,,,,return 假; ,,,} ,,,info 美元;=,getimagesize($文件); ,,,image 美元;=,& # 39;& # 39;; ,,,final_width 美元;=,0; ,,,final_height 美元;=,0; ,,,(width_old美元,,height_old美元)列表,=,美元信息; ,,,if (比例),{ ,,,,,if (width 美元;==,0),factor 美元;=,身高/height_old美元; ,,,,,elseif (height 美元;==,0),factor 美元;=,宽/width_old美元; ,,,,,else factor 美元;=,min (, width 美元/,width_old美元,美元height /, height_old美元),, ,,,,,final_width 美元;=,round (width_old 美元;*,因素美元); ,,,,,final_height 美元;=,round (height_old 美元;*,因素美元); ,,,} ,,,else {,,, ,,,,,final_width 美元;=,(=,width 美元;& lt; 0,), ?, width_old 美元;:,美元宽度; ,,,,,final_height 美元;=,(=,height 美元;& lt; 0,), ?, height_old 美元;:,美元的高度; ,,,} ,,,switch (信息[2],美元),{ ,,,,,case IMAGETYPE_GIF: ,,,,,,,image 美元;=,imagecreatefromgif($文件); ,,,,,休息; ,,,,,case IMAGETYPE_JPEG: ,,,,,,,image 美元;=,imagecreatefromjpeg($文件); ,,,,,休息; ,,,,,case IMAGETYPE_PNG: ,,,,,,,image 美元;=,imagecreatefrompng($文件); ,,,,,休息; ,,,,,默认值: ,,,,,,,return 假; ,,,} ,,,image_resized 美元;=,imagecreatetruecolor (, final_width美元,美元final_height ); ,,,if (,(美元信息[2],==,IMAGETYPE_GIF), | |,(美元信息[2],==,IMAGETYPE_PNG),), { ,,,,,trnprt_indx 美元;=,imagecolortransparent($形象); ,,,,,//,If have 我方表示歉意a specific transparent 颜色 ,,,,,if (trnprt_indx 美元;祝辞=,0),{ ,,,,,,,//,Get 从而original 图像# 39;s transparent 颜色# 39;s RGB 价值 ,,,,,,,trnprt_color 美元;,=,imagecolorsforindex($形象,trnprt_indx美元); ,,,,,,,//,Allocate 从而same color 拷贝,new image 资源 ,,,,,,,trnprt_indx 美元;,=,imagecolorallocate (image_resized美元,美元trnprt_color[& # 39;红色# 39;],,美元trnprt_color[& # 39;绿色# 39;],,美元trnprt_color[& # 39;蓝# 39;]); ,,,,,,,//,Completely fill 从而background of 从而new image with allocated 颜色。 ,,,,,,,imagefill (image_resized美元,,0,0),trnprt_indx美元); ,,,,,,,//,Set 从而background color for new image 用透明 ,,,,,,,imagecolortransparent (image_resized美元,,trnprt_indx美元); ,,,,,} ,,,,,//,Always make a transparent background color for PNGs that 不要# 39;t have one allocated 了 ,,,,,elseif (美元信息[2],==,IMAGETYPE_PNG), { ,,,,,,,//,Turn off transparency blending (暂时) null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null利用PHP怎么对png图像进行缩放