2013-03-06 68 views
0

我想弄清楚如何从更小的图像计算全尺寸图像的剪切坐标,可以说全尺寸图像是1775 x 2664,用户在剪裁页面上看到的图像(使用jCrop)是533 X 800计算作物坐标

小图像上的裁剪坐标是:20,11,230,305

(从左开始,从顶部开始,从左至右,从上端部)

我如何将坐标缩放为全尺寸图像。

我需要让用户在预览页面上选择图像的部分,然后用PHP来提取从全尺寸图像的图像的适当部分..

回答

1

给你一些参考: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); 
+0

这几乎是一样的东西我已经有了,但我不得不比翻倍,不可能找出原因,它是因为我在裁剪页面上使用的图像大小是50%。 – 2013-03-07 20:44:30

0

,应该工作:

left = 20 * (1775/533) 
top = 11 * (2664/800) 
right = 230 * (1775/533) 
bottom = 305 * (2664/800)