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

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
linjuming
Posts: 122
Joined: 2011-01-25T00:09:50-07:00
Authentication code: 8675308

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

Post 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'/>";

?>

User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

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

Post 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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
linjuming
Posts: 122
Joined: 2011-01-25T00:09:50-07:00
Authentication code: 8675308

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

Post by linjuming »

Thank you very much !
Post Reply