如何检测图像有多少种颜色,然后在PHP中返回这些颜色的RGB或十六进制值?标准的文件格式..。PNG、JPG、GIF等。
样品图像:
用于:,一种在线设计工具,允许您上传图像以供设计人员使用。我试图拒绝所有的图像超过10种颜色(或潜在的减少颜色?)对于少于10种颜色的图像,我试图返回存在的每种颜色的十六进制或RGB值(颜色越多,打印过程就越昂贵)。
发布于 2011-12-14 19:26:52
$gd = imagecreatefrompng($filename);
$width = imagesx($gd);
$height = imagesy($gd);
$colors = array();
for($x = 0; $x < $width; $x++)
{
for($y = 0; $y < $height; $y++)
{
$color = imagecolorat($gd, $x, $y);
$hex = sprintf("0x%06x", $color);
if(!in_array($hex, $colors))
{
$colors[] = $hex;
}
}
}
https://stackoverflow.com/questions/8510399
复制相似问题