0

I am trying to figure out how to calculate the cropping coordinates for the full size image from a much smaller image, lets say the full size image is 1775 x 2664, the image that the user sees on the cropping page (uses jCrop) is 533 X 800.

The cropping coordinates on the smaller image are: 20,11,230,305

(start from left, start from top, end from left, end from top)

How do i scale the coordinates to the full size image.

I need to allow the user to select the portion of the image on the preview page and then use php to extract the appropriate part of the image from the full size image..

2 Answers2

1

To give you some reference: http://en.wikipedia.org/wiki/Rule_of_three_%28mathematics%29#Rule_of_Three

// assuming fixed ratio on width and height
// which is the case in your example: ~33% for both dimensions
$FULL_WIDTH = 1775;
$SCALED_WIDTH = 533;

$ratio = $SCALED_WIDTH / $FULL_WIDTH;

$scaled_crop_coordinates = array(20, 11, 230, 305);

$full_crop_coordinates = array();
foreach($scaled_crop_coordinates as $val)
{
    $full_crop_coordinates[] = floor($val / $ratio);
}
var_dump($full_crop_coordinates);
Timothée Groleau
  • 1,940
  • 13
  • 16
  • This is almost the same as what i already had but i was having to double the ratio and couldnt figure out why, it was because the image i was using on the cropping page was 50% of the size.. – Dean Bayley Mar 07 '13 at 20:44
0

that should work:

left = 20 * (1775/533)
top = 11 * (2664/800)
right = 230 * (1775/533)
bottom = 305 * (2664/800)
bitWorking
  • 12,485
  • 1
  • 32
  • 38