有誰知道關聯下列代碼的數學公式嗎?代碼後面的數學公式
// 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 –