本文 24690 pv
1
imagecopyresampled($newim, $im, 0, 0, 7, 174, 120, 42, $new_img_width, $new_img_height); // 原始尺寸 120 x 42
imagecopyresampled($newim, $im, 0, 0, 100, 30, 500, 500, $new_img_width, $new_img_height); // 截取出来后放到 500 x 500
imagecopyresampled($newim, $im, 0, 0, 100, 30, 10, 10, $new_img_width, $new_img_height); // 截取出来后縮小到 10 x 10
原始代码如下:
PHP截取图片的某个区域
© kekehu / 技术资源 / 2009.10.19 / 23:23 / 24690PV
解釋一下主要参数:imagecopyresampled($newim, $im, 0, 0, 7, 174, 120, 42, $new_img_width, $new_img_height); // 原始尺寸 120 x 42
imagecopyresampled($newim, $im, 0, 0, 100, 30, 500, 500, $new_img_width, $new_img_height); // 截取出来后放到 500 x 500
imagecopyresampled($newim, $im, 0, 0, 100, 30, 10, 10, $new_img_width, $new_img_height); // 截取出来后縮小到 10 x 10
原始代码如下:
$filename = 'D:/ex.jpg'; /*读取图片 */ $im = imagecreatefromjpeg($filename); /* 图片要截多少, 长/宽 */ $new_img_width = 140; $new_img_height = 20; /* 先建立一个 新的空白图片档 */ $newim = imagecreatetruecolor($new_img_width, $new_img_height); // 输出图要从哪边开始x, y , 原始图要从哪边开始 x, y , 要输多大 x, y(resize) , 要抓多大 x, y imagecopyresampled($newim, $im, 0, 0, 329, 182, 140, 20, $new_img_width, $new_img_height); /* 放大 成 500 x 500 的图 */ //imagecopyresampled($newim, $im, 0, 0, 100, 30, 500, 500, $new_img_width, $new_img_height); /* 將图印出來 */ //$file = imagejpeg($newim,'',100); /* 保存图片 */ $to_File = 'D:/AppServ/www/ceshi/lin.jpeg'; ImageJpeg($newim,$to_File,100); /* 资源回收 */ imagedestroy($newim); imagedestroy($im);
2011.07.21 22:26
/* 將图印出來 */
//$file = imagejpeg($newim,'',100);
php手册,函数原型:
bool imagejpeg ( resource image [, string filename [, int quality]] )
请兄弟看一下