Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP在用户指定点周围创建缩略图_Php_Image Manipulation_Thumbnails_Crop - Fatal编程技术网

PHP在用户指定点周围创建缩略图

PHP在用户指定点周围创建缩略图,php,image-manipulation,thumbnails,crop,Php,Image Manipulation,Thumbnails,Crop,因此,我有一个用户图像和基于该图像的用户指定的兴趣点 我从一个XML文件中检索到了这个关注点,并将它们放入变量中,因此我有2个关注点 x=246 y=73 我的问题是:如何裁剪一个45×53的缩略图图像,而上面的坐标是缩略图的中心点?我根本不想让图像缩放,只想裁剪。使用GD时,它应该是这样工作的: // Open source image $srcImg = imagecreatefromjpeg ( $filename ); // Create new image for the cropp

因此,我有一个用户图像和基于该图像的用户指定的兴趣点

我从一个XML文件中检索到了这个关注点,并将它们放入变量中,因此我有2个关注点

x=246 y=73


我的问题是:如何裁剪一个45×53的缩略图图像,而上面的坐标是缩略图的中心点?我根本不想让图像缩放,只想裁剪。

使用GD时,它应该是这样工作的:

// Open source image
$srcImg = imagecreatefromjpeg ( $filename );

// Create new image for the cropped version
$destImg = imagecreate ( 45, 53 );

// Calculate the upper left of the image-part we want to crop
$startX = x - 45 / 2;
$startY = y - 53 / 2;

// Copy image part into the new image
imagecopy ( $destImg, $srcImg , 0, 0, $startX, $startY, 45, 53 );

// Write the new image with quality 90
imagejpeg($destImg, 'newfile.jpg', 90);

您可能需要检查圆角坐标,因为如果不这样做,图像可能会模糊。如果用户选择一个角点作为poi,您应该检查裁剪后的图像坐标是否在原始图像内。

通过搜索更容易找到答案您是否在php中安装了gd或imagick模块?