画像関係アルゴリズム †
白黒化、明るさの計算方法 †
単純に白黒化したい場合は、各色の平均値を求めるが、実際には各色が明るさに影響する割合が異なるため、以下のような式を用いる場合が多い。
明るさ=R×0.30+G×0.59+B×0.11
- google の枠色から白黒文字決定
sub get_powered_link_color {
my ($border_color) = @_;
my ($powered_link_color);
if ($border_color =~ /^#([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})$/) {
my ($r, $g, $b) = (hex $1, hex $2, hex $3);
if ($r * 0.3 + $g * 0.59 + $b * 0.11 < 127) {
$powered_link_color = '#FFFFFF';
} else {
$powered_link_color = '#000000';
}
}
return $powered_link_color;
}
補色 †
色相環で、対抗位置にある色。
テキスト色と背景色等を決める場合に、目立つようになる。
sub get_complementary_color {
my ($before_color) = @_;
my ($after_color);
if ($before_color =~ /^#([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})$/) {
my ($r, $g, $b) = (hex $1, hex $2, hex $3);
$after_color = sprintf "#%02lx%02lx%02lx", 255 - $r, 255 - $g, 255 - $b;
}
return $after_color;
}