1px yöntemin bir örneği:
<?php
$filename = $_GET['filename'];
$image = imagecreatefromjpeg($filename);
$width = imagesx($image);
$height = imagesy($image);
$pixel = imagecreatetruecolor(1, 1);
imagecopyresampled($pixel, $image, 0, 0, 0, 0, 1, 1, $width, $height);
$rgb = imagecolorat($pixel, 0, 0);
$color = imagecolorsforindex($pixel, $rgb);
?>
<html>
<head>
<title>Test Image Average Color</title>
</head>
<body style='background-color: rgb(<?php echo $color['red'] ?>, <?php echo $color['green'] ?>, <?php echo $color['blue'] ?>)'>
<form action='' method='get'>
<input type='text' name='filename'><input type='submit'>
</form>
<img src='<?php echo $filename ?>'>
</body>
</html>
Burada ortalama sınır ilk bağlantıya benzer renk bulmak için bazı örnek kod. kullanımınız için bu (Bu kod verimsiz olduğunu biliyorum ama umarım takip etmek kolaydır) iyi çalışabilir:
<?php
$filename = $_GET['filename'];
$image = imagecreatefromjpeg($filename);
$width = imagesx($image);
$height = imagesy($image);
for($y = 0; $y < $height; $y++){
$rgb = imagecolorat($image, 0, $y);
$color = imagecolorsforindex($image, $rgb);
$red += $color['red'];
$green += $color['green'];
$blue += $color['blue'];
$rgb = imagecolorat($image, $width -1, $y);
$color = imagecolorsforindex($image, $rgb);
$red += $color['red'];
$green += $color['green'];
$blue += $color['blue'];
}
for($x = 0; $x < $height; $x++){
$rgb = imagecolorat($image, $x, 0);
$color = imagecolorsforindex($image, $rgb);
$red += $color['red'];
$green += $color['green'];
$blue += $color['blue'];
$rgb = imagecolorat($image, $x, $height -1);
$color = imagecolorsforindex($image, $rgb);
$red += $color['red'];
$green += $color['green'];
$blue += $color['blue'];
}
$borderSize = ($height=$width)*2;
$color['red'] = intval($red/$borderSize);
$color['green'] = intval($green/$borderSize);
$color['blue'] = intval($blue/$borderSize);
?>
Güncelleme: Biraz more refined code on github koydu. Bu, hem sınırın ortalamasını hem de tüm görüntünün ortalamasını içerir. 1px'e yeniden boyutlandırmanın, her bir pikselin taranmasından çok daha fazla kaynak dostu olduğu belirtilmelidir (gerçek zamanlı testler yapmadığım halde), ancak kod üç farklı yöntemi göstermektedir.
Hiç bu işe yarıyor mu? –