|
Posted by Norman Peelman on 09/04/07 10:39
Nerd Monster wrote:
>> 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?
>
>
>
>
Ok, you switched your variable on me. :)
You need to:
if (baseconvert(...) > 512)
{
divide by 512;
}
if (new value > 128)
{
divide again by 128
)
something like that...
The hex numbers your passing in are too big. Must be 0-255 (0x00 - 0xFF)
Norm
Navigation:
[Reply to this message]
|