Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何知道图片中是否有颜色_Php_Image - Fatal编程技术网

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

如何知道在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,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,该函数用于
分配
,而不是
定位
:)