加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-12 21:00:32 所属栏目:PHP教程 来源:网络整理
导读:本篇章节讲解PHP实现对png图像进行缩放的方法。供大家参考研究。具体实现方法如下: = 0) { // Get the original image's transparent color's RGB values $trnprt_color = imagecolorsforindex($image,$trnprt_indx); // Allocate the same color i

本篇章节讲解PHP实现对png图像进行缩放的方法。分享给大家供大家参考。具体实现方法如下:

= 0) { // Get the original image's transparent color's RGB values $trnprt_color = imagecolorsforindex($image,$trnprt_indx); // Allocate the same color in the new image resource $trnprt_indx = imagecolorallocate($image_resized,$trnprt_color['red'],$trnprt_color['green'],$trnprt_color['blue']); // Completely fill the background of the new image with allocated color. imagefill($image_resized,$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't have one allocated already elseif ($info[2] == IMAGETYPE_PNG) { // Turn off transparency blending (temporarily) imagealphablending($image_resized,false); // Create a new transparent color for image $color = imagecolorallocatealpha($image_resized,127); // Completely fill the background of the new image with allocated color. imagefill($image_resized,$color); // Restore transparency blending imagesavealpha($image_resized,true); } } imagecopyresampled($image_resized,$image,$final_width,$final_height,$width_old,$height_old); if ( $delete_original ) { if ( $use_linux_commands ) exec('rm '.$file); else @unlink($file); } switch ( strtolower($output) ) { case 'browser': $mime = image_type_to_mime_type($info[2]); header("Content-type: $mime"); $output = NULL; break; case 'file': $output = $file; break; case 'return': 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; }

希望本文所述对大家的php程序设计有所帮助。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读