Page 1 of 1

[BUG] PixelSetColor for hexes with less than 6 characters

Posted: 2006-10-25T02:44:17-07:00
by theillustratedlife
I wrote a drawing engine in Flash that saves with GD2. I have been dissatisfied with its quality, so I thought I'd give MagickWand a try.

To go to and from sketchmaker.php, I have been using serialize() and unserialize(). My colors are generated in Flash as 0xFFFFFF values. After they are sent to PHP and unserialized, they become decimals, and I must run dechex to restore them. If I have any degree of red, I get a 6 character hex and this works great; however, if I use a blue or green tone without a red component, I get odd results. Green becomes yellow (perhaps 00FF55 is being read as FF5500?) and blue becomes black ( :?: ).

By restoring the hex to 6 characters, PixelSetColor works as advertised.

It could be argued that this is not MagickWand's fault; however, since PHP dechex throws away leading zeroes (and serialize/unserialize converts hex to decimals), it seems that MW should correctly interpret any hex <= 6 characters as its 6 character equivalent.

If anyone is having their colors mucked with going between Flash and ImageMagick/MagickWand, try this code:

Code: Select all

		$thiscolor="#";
		for($i=1; $i<=(6-strlen(dechex($thisline[0]))); $i++){
			$thiscolor.="0";
		}
		$thiscolor.=dechex($thisline[0]);
where $thisline[0] is the color you are trying to decode and $thiscolor is its 6-digit equivalent.