为照片找到匹配颜色的脚本

A script that finds a matching color to the photo

我是一名平面设计师,我经常制作网站。我正在寻找一个脚本(最终甚至可能是软件)来找到一种与照片匹配的颜色。一个很好的例子就是那个页面:https://unsplash.com/grid If refered your mouse on the picture it shows a matching color. This is a screenshoot that I show this issue: https://dl.dropboxusercontent.com/u/65947165/qu1.png

我会使用 ImageMagick 并通过将图像大小调整为 1 像素 x 1 像素并将该像素转换为文本来找到平均颜色,如下所示:

convert photo-1414637104192-f9ab9a0ee249.jpg -resize 1x1! -colorspace RGB txt:
# ImageMagick pixel enumeration: 1,1,255,rgb
0,0: (0,21,3)  #001503  rgb(0,21,3)

所以 rgb(0,21,3) 是您示例中带有水滴的绿叶。你可以像这样把它当作 sRGB:

convert photo-1418479631014-8cbf89db3431.jpg -resize 1x1! txt:
# ImageMagick pixel enumeration: 1,1,255,srgb
0,0: (141,109,91)  #8D6D5B  srgb(141,109,91)

如果你想要它作为图像,你会这样做:

convert photo-1414637104192-f9ab9a0ee249.jpg -resize 1x1! -scale 1000 output.jpg

这是示例页面中的第一张图片...

我真的不会说话PHP,但这应该很接近:

<?php 
$image = new Imagick('input.jpg'); 
$image->resizeImage(1,1,Imagick::FILTER_BOX,1);
$pixel = $image->getImagePixelColor(0,0); 
print $pixel->getColorAsString();
$colors = $pixel->getColor(); 
print_r($colors);
?>

输出

srgb(55.259%,42.2065%,34.9279%)Array
(
    [r] => 141
    [g] => 108
    [b] => 89
    [a] => 1
)