You are here: Re: newbie question - variable data types? « PHP Language « IT news, forums, messages
Re: newbie question - variable data types?

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация