我编写了一段代码,根据图像的背景颜色放置标志,如果背景较暗,它将放置浅色标志,如果背景较亮,它将放置深色标志。问题是,如果我放置标志的角落很暗,而整个背景很亮,那么它将放置深色标志,那么我该如何解决这个问题
以下是代码:
$filename = "logo_5.png";
list($width, $height) = getimagesize($filename);
$ratio = $height/$width;
$new_width = $frame_width;
$new_height = $frame_width * $ratio;
$temp_width = $frame_width/5;
$temp_height = $temp_width * $ratio;
$luminance = get_avg_luminance($target_file,10);
//echo "AVG LUMINANCE: $luminance<br />";
// assume a medium gray is the threshold, #acacac or RGB(172, 172, 172)
// this equates to a luminance of 170
if ($luminance > 170) {
$socials_footer = "socials_7.png";
} else {
$socials_footer = "socials_8.png";
}