php查询框,在PHP中查找图像边框颜色的算法

我试图找到一种方法来使用

PHP从图像中获取边框颜色

我试图使用这个代码,但这个algorathim给了我任何图像的所有颜色.

function colorPalette($imageFile, $numColors, $granularity = 5)

{

$granularity = max(1, abs((int)$granularity));

$colors = array();

$size = @getimagesize($imageFile);

if($size === false)

{

user_error("Unable to get image size data");

return false;

}

$img = @imagecreatefromjpeg($imageFile);

if(!$img)

{

user_error("Unable to open image file");

return false;

}

for($x = 0; $x < $size[0]; $x += $granularity)

{

for($y = 0; $y < $size[1]; $y += $granularity)

{

$thisColor = imagecolorat($img, $x, $y);

$rgb = imagecolorsforindex($img, $thisColor);

$red = round(round(($rgb['red'] / 0x33)) * 0x33);

$green = round(round(($rgb['green'] / 0x33)) * 0x33);

$blue = round(round(($rgb['blue'] / 0x33)) * 0x33);

$thisRGB = sprintf('%02X%02X%02X', $red, $green, $blue);

if(array_key_exists($thisRGB, $colors))

{

$colors[$thisRGB]++;

}

else

{

$colors[$thisRGB] = 1;

}

}

}

arsort($colors);

return array_slice(array_keys($colors), 0, $numColors);

}

// sample usage:

$palette = colorPalette('rmnp8.jpg', 10, 4);

echo "

foreach($palette as $color)

{

echo "

 #$color\n";

}

echo "

\n";

此外,我正在尝试使用它来构建像这些设计的设计.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值