我在我的文件系统上有一个图像。我使用裁剪工具将其显示在页面上,但是我会将其缩小以适合裁剪工具区域(如果图像比区域小,则将其拉伸以占据整个区域)。在这个页面上,用户将选择照片的一个区域来保存(使用jcrop)并提交。php缩放图像裁剪
在后端我会等待上一页的坐标。我会得到x1,x2,y1,y2,w和h。
问题是调整大小的图像上的坐标(向用户显示的坐标)不适用于全尺寸的图像,因为它们要么占一个小于图像的区域(它的大小被缩小以适合在屏幕上),或者它会比图像更大(它被拉伸以适应屏幕)。
我可以得到原始照片的高度和宽度,以及它被强制进入的静态宽度和高度。
如果给定已知尺寸,您会如何找到图像的正确区域?
我当前的代码是在这里
$target_width = 150;
$target_height = 150;
$jpeg_quality= 90;
$tmp =explode('/',$_POST['filename']);
$src = '../uploads/'.$tmp[count($tmp)-1];
$x1 = $_POST['x1'];
$x2 = $_POST['x2'];
$y1 = $_POST['y1'];
$y2 = $_POST['y2'];
$w = $_POST['w'];
$h = $_POST['h'];
$image = imagecreatefromjpeg($src);
$final = imagecreatetruecolor($target_width, $target_height);
imagecopyresampled($final, $image, 0, 0, $x1, $y1, $target_width, $target_height, $w, $h);
imagejpeg($final, $src, $jpeg_quality);