I have an image on my filesystem. I display it on a page with a cropping tool, but I size it down to fit into the cropping tool area (or stretch it to take up the whole area if the image is smaller than the area). On this page the user would select a region of the photo to keep (using jcrop) and submit.
On the backend I will be waiting for the coordinates from the previous page. I will get x1, x2, y1, y2, w, and h.
The problem is that the coordinates on the resized image (the one displayed to the user) are not readily usable on the full sized image as they will either account for a region smaller than the image (it was sized down to fit on the screen) or it will be larger than the image (it was stretched to fit on the screen).
I can get the height and width of the original photo as well as the static width and height it was forced into.
How would you find the correct region of the image given the known dimensions?
My current code is here
$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);
Maybe my question wasn’t very clear (I had trouble explaining to someone IRL as well) but my answer should clear it up pretty well.
I have an image on my filesystem (path is available to me at $_POST[‘image_path’]) and an image tag that looks like “”. I got the data from the image tag with some jquery magic.
‘Proportions’ is the answer.
The h_limit is the height constraint of the img tag
The w_limit is the width constraint of the img tag
And then I could just do