Detect main colors in an image with PHP

前端 未结 7 2175
走了就别回头了
走了就别回头了 2020-11-27 12:05

I am trying to replicate the functionality that Dribbble.com does with detecting the predominant colors in an Image. In the image below you can see a screenshot from Dribbb

7条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-27 12:21

    I have a Unix bash shell script with ImageMagick called dominantcolor that may do what you want. See my scripts web site at http://www.fmwconcepts.com/imagemagick/index.php. You an run it from PHP exec(). See my pointers for use on my home page.

    Input:

    dominantcolor -n 6 -p all -s save plate.png
    
    count,hexcolor
    586,#5ECADC
    520,#AFA85D
    469,#3C3126
    462,#B9C8BB
    258,#488A70
    205,#B06928
    


    The -n 6 is the desired number of colors in the color quantization. The -p all means print all counts and colors for the resulting 6 colors. The -s save indictates to save a swatch image.

    Colors below are shown with the dominant color on the left and decreasing count colors towards the right according to the list above.

提交回复
热议问题