Map resized image coordinates back to the original
So here is an interesting one (or at least I think it is).
Turns out that I have two copies of the same image, the original and one
resized to fit the window.
The user then creates a polygon over the resized version of the image and
with some javascript I send the coordinates to a php script which then
merges the polygon into the original image.
The problem is, the resized coordinates are not the same for the original
image, still there is a relation between them.
Here is the code of how I resize the image in js:
if(h > 610 || w > 815){
while(h > 610 || w > 815){
h = Math.ceil(h*0.80);
w = Math.ceil(w*0.80);
}
}
This code allows me to keep the image inside the workspace (which is 610 x
815) and at the same time keeping some aspect ratio.
Then in php I attempt to revert the resize within each coordinate, but
here is where Im stuck:
$values = array();
$num_points = count($polyCoords);
foreach($polyCoords as $coord){
array_push($values, intval($coord['x']) /* +- RELOCATE
FACTOR? */ );
array_push($values, intval($coord['y']) /* +- RELOCATE
FACTOR? */ );
}
Can someone give me a hand of how to calculate this "relocate factor" for
each point? I have the original size and the resized... size.
Any ideas will be must apreciated. Thanks.
No comments:
Post a Comment