|
Posted by Nerd Monster on 09/04/07 05:38
> Two problems:
>
> 1) 0xFF0000 = 16711680 (not 255 like you want)
> 2) Your second example is using a string (which equates to 0), not a
> hexadecimal value.
>
> As long as $hex is a string (as it should be coming in as
> GET/POST/REQUEST:
>
> This will work with or without adding '0x',
>
> $red = imagecolorallocate($im, 0, 0, base_convert($hex, 16, 10)/512/128))
>
> This will only work if you add '0x' to it:
>
> $red = imagecolorallocate($im, 0, 0, ($hex/512/128))
>
>
> Norm
Thanks Norm! Here's the problem, and you can test these complete examples on
your own machine to verify.
The following works correctly:
-----
<?php
$im = imagecreatetruecolor(100, 100);
$fillcolor = imagecolorallocate($im, 0, 0, 0x00FF00);
imagefill($im, 0, 0, $fillcolor);
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
-----
Using your example, the following does not work (assuming you pass $urlcolor
in the url):
------
<?php
$im = imagecreatetruecolor(100, 100);
$fillcolor = imagecolorallocate($im, 0, 0, base_convert($_GET["urlcolor"],
16, 10)/512/128);
imagefill($im, 0, 0, $fillcolor);
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
------
Any clues?
Navigation:
[Reply to this message]
|