2014-11-12 4 views
-2

PHP에서 색상이 있는지 확인하는 방법?그림에 색상이 있는지 알아 보는 방법

function colorIsInPicture('path/to/picture.jpg', '#f55'){ }  
+1

http://php.net/manual/en/function.imagecolorallocate.php – brandelizer

+0

지금까지 시도한 적이 있습니까? 이미지 주위에는 많은 PHP 함수가 있습니다 : http://php.net/manual/en/ref.image.php – Fluffeh

+2

그 함수는'locate'가 아니라'allocate'입니다. :) –

답변

0

한 가지 방법.

대상 픽셀을 찾고자하는 각 픽셀에 대해 반복합니다.

/** 
* 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; 
} 
관련 문제