1

I have an image 4x4 pixels, each pixel has the exact color that i want e.g #439902 etc,

I grab my image convert it to a palette using gd's imagetruecolortopalette() function, then i try to find the closest color in my image to another predefined color using imagecolorclosest() function, the problem is that it brings back a different color altogether, one thats not in my 4x4 image, the color is close to one of my colors but i need it exact.

I think the problem is that when i use to imagetruecolortopalette() function all the colors in my 4x4 image slightly change,

Is there a way round this problem.?

As an example...

if i Search for ( 66,100,39 ) my closest Match is: (76,90,56).

well 76,90,56 has changed because the colour was (78,98,43) in my original image. I know its not far out but i need it to stay the same

4

2 回答 2

0

如果您保存为 jpg,则可能是压缩问题;尝试另存为 png,因为它不压缩并且比 jpg 具有更多颜色。

从 IM 论坛中提取的一些代码:

exec("convert square.png[1x1+0+0] -format " .
     "\"%[fx:floor(255*u.r)],%[fx:floor(255*u.g)],%[fx:floor(255*u.b)]\" " .
     "info: 2>&1",$result);
      print_r($result);

我认为这里走错了路,因为这会识别颜色,这不是你想要的?

于 2012-06-10T19:45:56.983 回答
0

但是php已经有了这个功能:

图像颜色精确

于 2012-06-10T20:14:45.510 回答