Php 如何知道图片中是否有颜色
如何知道在PHP中图片中是否有颜色Php 如何知道图片中是否有颜色,php,image,Php,Image,如何知道在PHP中图片中是否有颜色 function colorIsInPicture('path/to/picture.jpg', '#f55'){ } 你需要用一个函数来检查每个像素的颜色 (示例#2)如果已安装,则可以使用一种方法 在每个像素上循环寻找目标颜色 /** * Warning: Untested, but *should* work. * Takes a path to the image file and a color in the form 'rgb(r,g
function colorIsInPicture('path/to/picture.jpg', '#f55'){ }
你需要用一个函数来检查每个像素的颜色
(示例#2)如果已安装,则可以使用一种方法 在每个像素上循环寻找目标颜色
/**
* Warning: Untested, but *should* work.
* Takes a path to the image file and a color in the form 'rgb(r,g,b)'.
* Left as exercise to reader to test and write any hex support for $sColor.
*/
function colorIsInPicture($sPath, $sColor)
{
$im = new Imagick($sPath);
$it = $im->getPixelIterator();
foreach($it as $row => $pixels)
foreach($pixels as $column => $pixel)
if($pixel->getColorAsString() == $sColor)
return true;
return false;
}
到目前为止你试过什么吗?关于图像有很多PHP函数:Brandelizer,该函数用于
分配
,而不是定位
:)