Created
January 19, 2015 12:49
-
-
Save zhoumengkang/ea07e13afe806634f31d to your computer and use it in GitHub Desktop.
尺寸匹配
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 先判定宽高比,再判定宽高 | |
$sizeArr = explode("x", $p['screen']); | |
$screenWidth = $sizeArr['0']; | |
$screenHeight = $sizeArr['1']; | |
if ($screenHeight) | |
$wh = $screenWidth / $screenHeight; | |
$tmpArr = array(); | |
// 根据 宽高比最小差值,宽最小差值,高最小差值 进行排序,顶部为最合适的尺寸 | |
foreach ($splashArr as $info) { | |
$tmp = abs($wh - $info['icon_width'] / $info['icon_height']) * 1000000; | |
$tmp += abs($screenWidth - $info['icon_width']); | |
$tmp += abs($screenHeight - $info['icon_height']); | |
$tmpArr[$tmp] = $info; | |
} | |
ksort($tmpArr); | |
// 最合适的尺寸列表,在前三条记录里,需要按宽再进行一次判定,防止出现上面宽的差值与高的差值相反的情况 | |
$cou = 0; | |
$tmp = null; | |
$useScreen = array(); | |
foreach ($tmpArr as $key => $info) { | |
if (++$cou > 3 ) { | |
break; | |
} | |
if (is_null($tmp) || $tmp > abs($screenWidth - $info['icon_width'])) { | |
$tmp = abs($screenWidth - $info['icon_width']); | |
$useScreen = $info; | |
} | |
} | |
$splashArr = $useScreen; | |
$op['splash']['url'] = $splashArr['icon_url']; | |
$op['splash']['start_ts'] = strtotime($splashArr['start_ts']); | |
$op['splash']['end_ts'] = strtotime($splashArr['end_ts']); | |
$op['splash']['display_time'] = $splashArr['display_time']; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment