Dribbble.com에서 수행하는 기능을 이미지의 주 색상을 감지하여 복제하려고합니다. 아래 이미지에서 Dribbble.com의 스크린 샷을 볼 수 있습니다.이 스크린 샷은 왼쪽 이미지의 8 가지 주요 색상을 보여줍니다. 다음은 이미지의 실제 페이지입니다. http://dribbble.com/shots/528033-Fresh-Easy?list=followingPHP로 이미지의 주 색상을 감지합니다.
PHP에서이 작업을 수행 할 수 있어야합니다. 필요한 색상을 얻을 수 있어야 데이터베이스에 저장할 수 있으므로 모든 페이지에서 처리 할 필요가 없습니다. 하중.
이미지에서 이러한 색상을 얻는 방법에 대한 연구가 끝난 후 일부 사람들은 픽셀 단위로 이미지를 검토 한 다음 가장 많이 발생하는 색상을 저장한다고 말했습니다. 다른 사람들은 더 많은 것이 있다고 말합니다. 가장 빈번하게 존재하는 색상을 얻는 것이 원하는 영향을주지는 못합니다. 그들은 당신이 이미지/색상을 Quantize 할 필요가 있다고 말합니다 (나는이 시점에서 길을 잃었습니다). 아래 같은 일을하는 자바 스크립트 라이브러리, 해당 페이지는 내가 quantize.js
라는 자바 스크립트 파일이 볼 수있는 페이지의 소스보기 여기 http://lokeshdhakar.com/projects/color-thief/
볼 수있는 드리블 슛 아래 이미지에서
및 결과는 정말 좋습니다. 그래서 나는 PHP와 이미지의 색상을 반환하고 계산합니다이 기능을 발견했다를 PHP와 자바 스크립트 라이브러리가 있지만, 무엇을 그렇게 할 수 있기를 희망하고 GD/ImageMagick를하고있다 하지만 결과는 위의 자바 스크립트 버전과 다른과 드리블이 사람이 내가 PHP와 같은 작업을 할 수있는 방법을 알고있는 경우
/**
* Returns the colors of the image in an array, ordered in descending order, where the keys are the colors, and the values are the count of the color.
*
* @return array
*/
function Get_Color()
{
if (isset($this->image))
{
$PREVIEW_WIDTH = 150; //WE HAVE TO RESIZE THE IMAGE, BECAUSE WE ONLY NEED THE MOST SIGNIFICANT COLORS.
$PREVIEW_HEIGHT = 150;
$size = GetImageSize($this->image);
$scale=1;
if ($size[0]>0)
$scale = min($PREVIEW_WIDTH/$size[0], $PREVIEW_HEIGHT/$size[1]);
if ($scale < 1)
{
$width = floor($scale*$size[0]);
$height = floor($scale*$size[1]);
}
else
{
$width = $size[0];
$height = $size[1];
}
$image_resized = imagecreatetruecolor($width, $height);
if ($size[2]==1)
$image_orig=imagecreatefromgif($this->image);
if ($size[2]==2)
$image_orig=imagecreatefromjpeg($this->image);
if ($size[2]==3)
$image_orig=imagecreatefrompng($this->image);
imagecopyresampled($image_resized, $image_orig, 0, 0, 0, 0, $width, $height, $size[0], $size[1]); //WE NEED NEAREST NEIGHBOR RESIZING, BECAUSE IT DOESN'T ALTER THE COLORS
$im = $image_resized;
$imgWidth = imagesx($im);
$imgHeight = imagesy($im);
for ($y=0; $y < $imgHeight; $y++)
{
for ($x=0; $x < $imgWidth; $x++)
{
$index = imagecolorat($im,$x,$y);
$Colors = imagecolorsforindex($im,$index);
$Colors['red']=intval((($Colors['red'])+15)/32)*32; //ROUND THE COLORS, TO REDUCE THE NUMBER OF COLORS, SO THE WON'T BE ANY NEARLY DUPLICATE COLORS!
$Colors['green']=intval((($Colors['green'])+15)/32)*32;
$Colors['blue']=intval((($Colors['blue'])+15)/32)*32;
if ($Colors['red']>=256)
$Colors['red']=240;
if ($Colors['green']>=256)
$Colors['green']=240;
if ($Colors['blue']>=256)
$Colors['blue']=240;
$hexarray[]=substr("0".dechex($Colors['red']),-2).substr("0".dechex($Colors['green']),-2).substr("0".dechex($Colors['blue']),-2);
}
}
$hexarray=array_count_values($hexarray);
natsort($hexarray);
$hexarray=array_reverse($hexarray,true);
return $hexarray;
}
else die("You must enter a filename! (\$image parameter)");
}
그래서 내가 부탁하고 결과? 당신이 알고있는 이미 존재하는 어떤 것 또는 나에게 이것에 대한 한 걸음 더 가까이 다가 가기위한 어떤 조언도 인정 될 것입니다.
http://stackoverflow.com/questions/3468500/detect-overall-average-color-of-the-picture –
@aSeptik 이미 게시 한 코드와 동일하게 보이게됩니다. – JasonDavis
시도해 보셨습니까? ''이미지에서 컬러 팔레트 가져 오기 ''를 위해 google 검색 ""나는 많은 결과를 창출했다. 그냥 묻고 ... –