赞
踩
public function cutImg($target_width,$target_height,$source_x,$source_y,$source_path) { $source_info = getimagesize($source_path); //获取图像信息 $source_mime = $source_info['mime']; // 文件类型 $cropped_width = $target_width; //截取的宽 $cropped_height = $target_height; //截取的高 switch ($source_mime) { case 'image/gif': $source_image = imagecreatefromgif($source_path); break; case 'image/jpeg': $source_image = imagecreatefromjpeg($source_path); break; case 'image/png': $source_image = imagecreatefrompng($source_path); break; default: return false; break; } imagesavealpha($source_image, true); // 保留源图片透明度 $cropped_image = imagecreatetruecolor($cropped_width, $cropped_height); $color=imagecolorallocatealpha($cropped_image,0,0,0,127); //创建颜色 imagefill($cropped_image, 0, 0, $color); //设置白底 // 裁剪 imagecopy($cropped_image, $source_image, 0, 0, $source_x, $source_y, $cropped_width,$cropped_height); $alpha = imagecolorallocatealpha($cropped_image, 0, 0, 0, 127);//透明 imagecolortransparent($cropped_image,$alpha); //3.设置透明色 imagefill($cropped_image, 0, 0, $alpha); //保存图片到本地 $res = imagepng($cropped_image,'a.png'); }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。