Page 1 of 1

how to get the color value of a point (2)?

Posted: 2011-10-27T04:28:38-07:00
by linjuming
refer to older question:

how to get the color value of a point?


then i want to enlarge the png border,but the result png border color is not the same with older one.
Image

the source kk.png:
Image

Code: Select all


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

	include_once("../color_converter/color_converter.class.php");
	$rgb=explode(",",$result[0]);
	$cc=new colorConverter();
	$hex=$cc->RGB2HEX($rgb[0],$rgb[1],$rgb[2]);
	$rgb_str=$result[0];
	echo "rgb_str = $result[0]<br>";
	echo "array   = ";print_r($rgb);
	echo "<br>hex = $hex<br>";

	exec("convert kk.png -crop 198x198+1+1 laji.png 2>&1",$err);
	exec("convert laji.png -bordercolor rgb($result[0]) -border 10x10 laji.png");
	echo "<img src='kk.png'/>";
	echo "<img src='laji.png'/>";

?>


Re: how to get the color value of a point (2)?

Posted: 2011-10-27T05:04:28-07:00
by anthony
Using a '[1x1] means resize the image to just 1 pixel. The resulting color will be an average of all the colors in the image (no exactly that due to the exact resize filter being used).

To get the color of just the top left pixel, you need a crop varient of read modifier. '[1x1+0+0]'

See IM examples, File Handling, Read Modifiers
http://www.imagemagick.org/Usage/files/#read_mods

Re: how to get the color value of a point (2)?

Posted: 2011-10-27T05:38:23-07:00
by linjuming
Thank you very much !