|
面向脚本之家 jb51.cc编程,下面跟随脚本之家 jb51.cc的小编来举个例子吧。 经测试代码如下:
/**
* 裁剪、缩放图片
*
* @author 脚本之家 jb51.cc jb51.cc
* @param string $src_image 原始图
* @param string $dst_path 裁剪后的图片保存路径
* @param int $dst_x 新图坐标x
* @param int $dst_y 新图坐标y
* @param int $src_x 原图坐标x
* @param int $src_y 原图坐标y
* @param int $dst_w 新图宽度
* @param int $dst_h 新图高度
* @param int $src_w 原图宽度
* @param int $src_h 原图高度
*/
function imageCropAndResize($src_image,$dst_path,$dst_x,$dst_y,$src_x,$src_y,$dst_w,$dst_h,$src_w,$src_h) {
if (function_exists('imagecreatefromstring')) {
$src_img = imagecreatefromstring(file_get_contents($src_image));
} else {
return false;
}
if (function_exists('imagecopyresampled')) {
$new_img = imagecreatetruecolor($dst_w,$dst_h);
imagecopyresampled($new_img,$src_img,$src_h);
} elseif (function_exists('imagecopyresized')) {
$new_img = imagecreate($dst_w,$dst_h);
imagecopyresized($new_img,$src_h);
} else {
return false;
}
switch (getFileSuffix($dst_path)) {
case 'png':
if (function_exists('imagepng') && imagepng($new_img,$dst_path)) {
ImageDestroy($new_img);
return true;
} else {
return false;
}
break;
case 'jpg':
default:
if (function_exists('imagejpeg') && imagejpeg($new_img,$dst_path)) {
ImageDestroy($new_img);
return true;
} else {
return false;
}
break;
case 'gif':
if (function_exists('imagegif') && imagegif($new_img,$dst_path)) {
ImageDestroy($new_img);
return true;
} else {
return false;
}
break;
}
} (编辑:安卓应用网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|