解释一下主要参数:
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); |