質問
PHPでODP-> HTML変換を行っています。以下に問題があります。
スタイルを使用してください:Window-font-colorプロパティを使用して、窓の前景色が明るい背景色の前景色として使用し、暗い背景色の場合は白かを指定します。
(OpenDocument仕様バージョン1.0、15.4.4)
背景画像がある場合、この画像が明るいか暗いかどうかを確認するにはどうすればよいですか?
あなたはなにか考えはありますか?
よろしくお願いします、レブ
解決
これは解決するのに非常に興味深い問題だと思ったので、簡単なスクリプトをハックしてそれを行うことができました。提供された他の提案に従ってください
<?php
// TODO supply your own filenames
$filenames = array(
'testpics/client-bella-vi.jpg',
'testpics/istockphoto_8577991-concept-of-business-people-crowd.jpg',
'testpics/medium-gray.jpg');
// loop though each file
foreach ($filenames as $filename) {
echo "$filename<br/>";
$luminance = get_avg_luminance($filename,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) {
echo "Black Text<br />";
} else {
echo 'White Text<br />';
}
echo "<br />";
}
exit;
// get average luminance, by sampling $num_samples times in both x,y directions
function get_avg_luminance($filename, $num_samples=10) {
$img = imagecreatefromjpeg($filename);
$width = imagesx($img);
$height = imagesy($img);
$x_step = intval($width/$num_samples);
$y_step = intval($height/$num_samples);
$total_lum = 0;
$sample_no = 1;
for ($x=0; $x<$width; $x+=$x_step) {
for ($y=0; $y<$height; $y+=$y_step) {
$rgb = imagecolorat($img, $x, $y);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
// choose a simple luminance formula from here
// http://stackoverflow.com/questions/596216/formula-to-determine-brightness-of-rgb-color
$lum = ($r+$r+$b+$g+$g+$g)/6;
$total_lum += $lum;
// debugging code
// echo "$sample_no - XY: $x,$y = $r, $g, $b = $lum<br />";
$sample_no++;
}
}
// work out the average
$avg_lum = $total_lum/$sample_no;
return $avg_lum;
}
他のヒント
ピクセルの輝度を調べ、平均画像の明るさを計算する画像処理アルゴリズムを使用する可能性があります。
このドキュメントはあなたを開始します:
http://www.kweii.com/site/color_theory/2007_lv/brightnesscalculation.pdf
GDを使用したい場合は、使用しようとしています imagecolorat
画像のピクセルをサンプリングします。 PHP Manページに示されているように、色のRGBを決定できます。
次に、RGBサンプルを使用して、 基本的な輝度式.
明るいと考えるもののしきい値を決定し、それに応じて分類します。
所属していません StackOverflow