PHP 剪切图片
/** * [tailoringImg 去除图片左下角的水印部分] * @param string $file_path [图片路径] * @param int $save_width 保存图片宽度 * @param int $start_spot_x 开始剪切的X坐标 * @param int $start_spot_y 开始剪切的Y坐标 * @param int $width 剪切的宽度 * @param int $height 剪切的高度 * @param int $display 是否展示图片 */ function tailoringImg($file_path, $save_width, $start_spot_x, $start_spot_y, $width, $height, $display = 1) { if (file_exists($file_path) && is_readable($file_path)) { //从字符串中的图像流新建一图像 $src = imagecreatefromstring(file_get_contents($file_path)); //保存图片的高 $save_height = round($save_width * $height / $width); //根据要保存的宽和高创建图片 $new_image = imagecreatetruecolor($save_width, $save_height); //生成最后的图片 // dst_image 目标图象连接资源。 //src_image 源图象连接资源。 //dst_x 目标 X 坐标点。 //dst_y 目标 Y 坐标点。 //src_x 源的 X 坐标点。 //src_y 源的 Y 坐标点。 //dst_w 目标宽度。 //dst_h 目标高度。 //src_w 源图象的宽度。 //src_h 源图象的高度。 imagecopyresampled($new_image, $src, 0, 0, $start_spot_x, $start_spot_y, $save_width, $save_height, $width, $height); //header('Content-Type: image/jpeg'); imagejpeg($new_image, $file_path, 80); imagedestroy($src); imagedestroy($new_image); } }