我想用PHP裁剪图像并保存文件。我知道您应该使用GD库,但我不确定如何使用。有任何想法吗?
谢谢
您可以imagecopy用来裁剪图像的必需部分。该命令如下所示:
imagecopy
imagecopy ( resource $dst_im - the image object , resource $src_im - destination image , int $dst_x - x coordinate in the destination image (use 0) , int $dst_y - y coordinate in the destination image (use 0) , int $src_x - x coordinate in the source image you want to crop , int $src_y - y coordinate in the source image you want to crop , int $src_w - crop width , int $src_h - crop height )
来自PHP.net的代码- 从源图像中裁剪出一个80x40像素的图像
<?php // Create image instances $src = imagecreatefromgif('php.gif'); $dest = imagecreatetruecolor(80, 40); // Copy imagecopy($dest, $src, 0, 0, 20, 13, 80, 40); // Output and free from memory header('Content-Type: image/gif'); imagegif($dest); imagedestroy($dest); imagedestroy($src); ?>