失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > PHP实现对png图像进行缩放办法(支持透明背景) png缩放

PHP实现对png图像进行缩放办法(支持透明背景) png缩放

时间:2022-03-22 04:41:45

相关推荐

PHP实现对png图像进行缩放办法(支持透明背景) png缩放

php教程|php手册

PHP,png,缩放,png图片

php教程-php手册

PHP实现对png图像进行缩放的方法(支持透明背景),png缩放

复制别人源码,vscode简历,ubuntu 黑苹果,tomcat基线,创建本地sqlite,阿里云的服务器 备案流程,ui jquery插件下载,前端的框架软件,python 爬虫 慕课,php xor,seo公司服务,仿阿里微微网站源代码下载,网页如何判断百度蜘蛛,黑色 网站模板,手机查看页面源码,java旅游管理系统模板下载,thinkphp5 小程序商城lzw

本文实例讲述了PHP实现对png图像进行缩放的方法。分享给大家供大家参考。具体实现方法如下:

多店铺三级分销源码,vscode运行多个文件,git ubuntu对应,ecs tomcat7,sqlite 全文索引用法,生命因突破而精彩 飞蝶与爬虫,php文本数据库,seo翻译中文快速推广,小说网站源码,网页设计怎么更新模板lzw

function smart_resize_image( $file, $width = 0, $height = 0, $proportional = false, $output = file, $delete_original = true, $use_linux_commands = false ){ if ( $height <= 0 && $width <= 0 ) {return false; } $info = getimagesize($file); $image = \; $final_width = 0; $final_height = 0; list($width_old, $height_old) = $info; if ($proportional) {if ($width == 0) $factor = $height/$height_old;elseif ($height == 0) $factor = $width/$width_old;else $factor = min ( $width / $width_old, $height / $height_old); $final_width = round ($width_old * $factor);$final_height = round ($height_old * $factor); } else {$final_width = ( $width <= 0 ) ? $width_old : $width;$final_height = ( $height = 0) { // Get the original images transparent colors RGB values $trnprt_color = imagecolorsforindex($image, $trnprt_indx); // Allocate the same color in the new image resource $trnprt_indx = imagecolorallocate($image_resized, $trnprt_color[ ed], $trnprt_color[green], $trnprt_color[lue]); // Completely fill the background of the new image with allocated color. imagefill($image_resized, 0, 0, $trnprt_indx); // Set the background color for new image to transparent imagecolortransparent($image_resized, $trnprt_indx);}// Always make a transparent background color for PNGs that don have one allocated alreadyelseif ($info[2] == IMAGETYPE_PNG) { // Turn off transparency blending (temporarily) imagealphablending($image_resized, false); // Create a new transparent color for image $color = imagecolorallocatealpha($image_resized, 0, 0, 0, 127); // Completely fill the background of the new image with allocated color. imagefill($image_resized, 0, 0, $color); // Restore transparency blending imagesavealpha($image_resized, true);} } imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $final_width, $final_height, $width_old, $height_old); if ( $delete_original ) {if ( $use_linux_commands ) exec( m .$file);else @unlink($file); } switch ( strtolower($output) ) {case rowser: $mime = image_type_to_mime_type($info[2]); header("Content-type: $mime"); $output = NULL;break;case file: $output = $file;break;case eturn: return $image_resized;break;default:break; } switch ($info[2] ) {case IMAGETYPE_GIF: imagegif($image_resized, $output);break;case IMAGETYPE_JPEG: imagejpeg($image_resized, $output);break;case IMAGETYPE_PNG: imagepng($image_resized, $output);break;default: return false; } return true;}

卡盟排行榜新版源码,ubuntu 扩展ipad,业务模块部署了tomcat,骷髅爬虫玩家,php中的字符串截取,seo一般多久才能见效lzw

如果觉得《PHP实现对png图像进行缩放办法(支持透明背景) png缩放》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。