說明
bool imagecopy (resource $dst_im,resource $src_im,int $dst_x ,int $dst_y ,int $src_x ,int $src_y , int $src_w , int $src_h )
將 src_im 圖像中坐標從 src_x,src_y 開始,
寬度為 src_w,高度為 src_h 的一部分拷貝到
dst_im 圖像中坐標為 dst_x 和 dst_y 的位置上。
簡單和基本的圖像裁剪
<?php
// Original image
$filename = 'someimage.jpg';
// Get dimensions of the original image
list($current_width, $current_height) = getimagesize($filename);
// The x and y coordinates on the original image where we
// will begin cropping the image
$left = 50;
$top = 50;
// This will be the final size of the image (e.g. how many pixels
// left and down we will be going)
$crop_width = 200;
$crop_height = 200;
// Resample the image
$canvas = imagecreatetruecolor($crop_width, $crop_height);
$current_image = imagecreatefromjpeg($filename);
imagecopy($canvas, $current_image, 0, 0, $left, $top, $current_width, $current_height);
imagejpeg($canvas, $filename, 100);
?>