note 97920 added to function.imagecreatetruecolor
| From: | AndreasA dot at osu1 dot php dot net | Date: | Sun, 16 May 2010 00:06:49 +0000 |
| Subject: | note 97920 added to function.imagecreatetruecolor | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-169295@lists.php.net to get a copy of this message | ||
Just a little code-snippet. That make it easy to design your homepage and customize your style
rapidly.
<?php
$gradient=@imagecreatetruecolor(
($_GET["orientation"]=="vertical"? 1:(int)$_GET["pixel"]),
($_GET["orientation"]=="horizontal"? 1:(int)$_GET["pixel"]))
or $gradient=@imagecreate(
($_GET["orientation"]=="vertical"? 1:$_GET["pixel"]),
($_GET["orientation"]=="horizontal"? 1:$_GET["pixel"]))
or exit("error");
for($xy=0; $xy<(int)$_GET["pixel"]; $xy++)
imageline($gradient,
($_GET["orientation"]=="vertical"?0:$xy),
($_GET["orientation"]=="horizontal"?0:$xy),
($_GET["orientation"]=="vertical"?0:$xy),
($_GET["orientation"]=="horizontal"?0:$xy),
imagecolorallocate($gradient,
round(
hexdec(substr($_GET["color1"], 0, 2))-
(
hexdec(substr($_GET["color1"], 0, 2))
-hexdec(substr($_GET["color2"], 0, 2)))
/($_GET["pixel"]-1)*$xy),
round(
hexdec(substr($_GET["color1"], 2, 2))-
(
hexdec(substr($_GET["color1"], 2, 2))
-hexdec(substr($_GET["color2"], 2, 2)))
/($_GET["pixel"]-1)*$xy),
round(
hexdec(substr($_GET["color1"], 4, 2))-
(
hexdec(substr($_GET["color1"], 4, 2))-
hexdec(substr($_GET["color2"], 4, 2)))
/($_GET["pixel"]-1)*$xy)));
@header("Content-type: image/png");
imagepng($gradient);
imagedestroy($gradient);
?>
colorgradient.php?orientation=vertical&pixel=12& color1=ffffff&color2=000000 will output
a 1 pixel width, 12 pixel height, color gradient from black to white.
If you want to hide from your clients, that you use php for generating the color gradient, just add
following to your .htaccess:
RewriteEngine On
RewriteRule ^colorgradient_
(vertical|horizontal)_
([1-9]{1}[0-9]*)_
([a-f0-9]{6})_
([a-f0-9]{6})\.png$
colorgradient.php?
orientation=$1&
pixel=$2&
color1=$3&
color2=$4 [L]
And you only have to call colorgradient_vertical_12_ffffff_000000.png and it will be redirected to
the file above.
I hope you can use this script above for your projects!
I'm sorry for the new lines... The code was too compact ;) for php.net...
----
Server IP: 85.214.154.209
Probable Submitter: 95.118.24.160
----
Manual Page -- http://www.php.net/manual/en/function.imagecreatetruecolor.php
Edit -- https://master.php.net/note/edit/97920
Del: integrated -- https://master.php.net/note/delete/97920/integrated
Del: useless -- https://master.php.net/note/delete/97920/useless
Del: bad code -- https://master.php.net/note/delete/97920/bad+code
Del: spam -- https://master.php.net/note/delete/97920/spam
Del: non-english -- https://master.php.net/note/delete/97920/non-english
Del: in docs -- https://master.php.net/note/delete/97920/in+docs
Del: other reasons-- https://master.php.net/note/delete/97920
Reject -- https://master.php.net/note/reject/97920
Search -- https://master.php.net/manage/user-notes.php