Page 1 of 1

how to color a black-none png file?

Posted: 2011-09-20T20:27:45-07:00
by linjuming

Code: Select all

<?php
	$color="A3E7EF";
	include_once("../color_converter/color_converter.class.php");
	$cc=new colorConverter;
	$hsl=$cc->HEX2HSL($color);
	$h=$hsl[0]/360*100;

	exec("convert 1.png -colorspace hsl " .
			"-channel r -evaluate set $h% +channel " .
			"-channel g -evaluate set $hsl[1]% +channel " .
			"a.png");
	echo "<img src='1.png' /><img src='a.png' />";
	echo "<br>";

	exec("convert -size 100x100 gradient:black-none 2.png");
	exec("convert 2.png -colorspace hsl " .
			"-channel r -evaluate set $h% +channel " .
			"-channel g -evaluate set $hsl[1]% +channel " .
			"b.png");
	echo "<img src='2.png' /><img src='b.png' /> ";

	exec("convert -size 100x100 gradient:black-red 3.png");
	exec("convert 3.png -colorspace hsl " .
			"-channel r -evaluate set $h% +channel " .
			"-channel g -evaluate set $hsl[1]% +channel " .
			"c.png");
	echo "<img src='3.png' /><img src='c.png' />";
?>
Image

Re: how to color a black-none png file?

Posted: 2011-09-20T21:25:12-07:00
by fmw42
Not quite sure I follow what you are doing? What is the goal of your processing?
exec("convert 3.png -colorspace hsl " .
"-channel r -evaluate set $h% +channel " .
"-channel g -evaluate set $hsl[1]% +channel " .
"c.png");
exec("convert 2.png -colorspace hsl " .
"-channel r -evaluate set $h% +channel " .
"-channel g -evaluate set $hsl[1]% +channel " .
"b.png");
These results are still in HSL space. Don't you need to convert back to RGB? Furthermore, your gradient:black-none has an alpha channel and it may be getting lost by the HSL conversion.

Re: how to color a black-none png file?

Posted: 2011-09-22T17:47:03-07:00
by anthony
Saving to PNG automatically converts back to RGB colorspace.

However it should be pointed out that HSL is (mostly) linear, as is RGB. You will probably want to adjust the results to be sRGB. Adding a -gamma 2.2 after converting to RGB colorspace is probably the simplest way to do this in IMv6, and generally close enough to sRGB for most purposes.

See the new section on IM Examples... Human Color Perception
http://www.imagemagick.org/Usage/color_ ... perception

IMv7 would probably be more automatic, unless sRGB default handling is turned off (for mathematical image processing)


As to the actual problem, I think a clear explanation of what you are trying to do will be needed for us to help you.

However I can tell you why you don't get the full result. You set hue, and saturation, but your luminance is still set to zero which is black for all hues and saturations! As such you gradient remains black!

For an example of working with other colorspaces see.. Gradients in other Colorspaces
http://www.imagemagick.org/Usage/canvas ... colorspace
Also see...
http://www.imagemagick.org/Usage/color_ ... colorwheel

Re: how to color a black-none png file?

Posted: 2011-09-22T18:06:38-07:00
by fmw42
Anthony wrote:Saving to PNG automatically converts back to RGB colorspace.
How do you know that? I would have expected to have a PNG image where red was hue, green was saturation and blue was lightness.

Testing:

convert rose: -colorspace HSL rose_hsl.png

does indeed show that the result is the same as rose:

Seems to be the case for .tiff and .jpg. This is something I would not have expected. I guess to get what I expect, I would have to use -separate and then -combine without setting the colorspace.

convert rose: -colorspace HSL -separate -combine rose_hsl2.png

Indeed, that does what I had expected from the -colorspace alone.

Learned something new today!

Re: how to color a black-none png file?

Posted: 2011-09-22T18:13:52-07:00
by anthony
Basically if the format can not handle a specific color space IM converts it.

PNG, JPEG, and TIFF does not handle HSL colorspaces, unless a color profile is provided to make it so.
All file formats assume the colorspace is sRGB unless the profile is provided, so IM caters to that assumption.

Re: how to color a black-none png file?

Posted: 2011-09-22T20:20:33-07:00
by linjuming
However I can tell you why you don't get the full result. You set hue, and saturation, but your luminance is still set to zero which is black for all hues and saturations! As such you gradient remains black!
thank you , this is the point.