有谁知道关联下列代码的数学公式吗?代码后面的数学公式
// aspect ratio <
$src_pos = array(0, (($new_size[1] - $thumb_height) * ($src_size[1] /$new_size[1]))/2);
// aspect ratio >
$src_pos = array((($new_size[0] - $thumb_width) * ($src_size[0]/$new_size[0]))/2, 0);
他们是从上传的图片创建拇指更宽的脚本中:
//variables
$src_size = getimagesize($_FILES["file"]["name"]);
$thumb_width = 250;
$thumb_height = 200;
$src_aspect = round(($src_size[0]/$src_size[1]), 1);
$thumb_aspect = round(($thumb_width/$thumb_height), 1);
if ($src_aspect < $thumb_aspect){
//higher
$new_size = array($thumb_width,($thumb_width/$src_size[0]) * $src_size[1]);
$src_pos = array(0, (($new_size[1] - $thumb_height) * ($src_size[1] /$new_size[1]))/2);
}else if($src_aspect > $thumb_aspect){
//wider
$new_size = array(($thumb_width/$src_size[1]) * $src_size[0], $thumb_height);
$src_pos = array((($new_size[0] - $thumb_width) * ($src_size[0]/$new_size[0]))/2, 0);
}else{
//same shape
$new_size = array($thumb_width, $thumb_height);
$src_pos = array(0, 0);
}
if ($new_size[0] < 1) $new_size[0] = 1;
if ($new_size[1] < 1) $new_size[1] = 1;
//creation of thumb
$thumb = imagecreatetruecolor($thumb_width, $thumb_height);
imagecopyresampled($thumb, $src, 0, 0, $src_pos[0], $src_pos[1], $new_size[0], $new_size[1], $src_size[0], $src_size[1]);
我STUDING这个剧本,但我无法理解的两行代码后面我在开始写的逻辑这个问题,所以我想知道他们与哪个数学公式有关。
看起来像PHP所以我添加了TAG来启用语法高亮如果你有不同的语言改变你正在使用的语言的TAG – Spektre
O对不起,它是PHP –