note 74488 added to function.imagesetpixel
| From: | GustsKaksis at osu1 dot php dot net | Date: | Fri, 13 Apr 2007 14:29:50 +0000 |
| Subject: | note 74488 added to function.imagesetpixel | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-125363@lists.php.net to get a copy of this message | ||
This code generate a simple colortable - not a very acurate one (it would be good to define fade of
color - more fading)
<?php
set_time_limit(200);
/*
Custommize this to see some nice changes:
*/
$width = 360; // degrees
$height = 18; // byte
$offset = -60; // offset of color hue
/*
Main programm:
Here comes transformations - width to degrees and height to intesity
*/
$w2deg = $width/360;
$h2byte = $height/255;
$byte2deg = 255/360;
$im = imagecreatetruecolor($width,$height);
for ($x = 0; $x < $width; $x ++){
/*
Transform X to degrees
*/
$x_pos = $x/$w2deg;
/*
Intensity position (where max intensity is 255) on 360 degree scale.
0 = red
1 = green
2 = blue
*/
$rgb_pos[0] = sin(deg2rad($x_pos) - deg2rad($offset + 0));
$rgb_pos[1] = sin(deg2rad($x_pos) - deg2rad($offset + 120));
$rgb_pos[2] = sin(deg2rad($x_pos) - deg2rad($offset + 240));
/*
Calculate intesity at current point 0 - 255
*/
$rgb_col[0] = 127 + 127 * $rgb_pos[0];
$rgb_col[1] = 127 + 127 * $rgb_pos[1];
$rgb_col[2] = 127 + 127 * $rgb_pos[2];
/*
White -> color -> Black loop
*/
for ($y = 0; $y < $height; $y ++){
/*
Transform Y to intensity (-255 to 255)
*/
$y_pos = -255 + ($y/$h2byte) * 2;
$rgb_out[0] = $rgb_col[0] - $y_pos;
$rgb_out[1] = $rgb_col[1] - $y_pos;
$rgb_out[2] = $rgb_col[2] - $y_pos;
/*
If we go over 255 or under 0 we normalize it
*/
foreach($rgb_out as $key => $col){
if ($col > 255){
$rgb_out[$key] = 255;
} else if ($col < 0){
$rgb_out[$key] = 0;
}
}
/*
Put a pixel
*/
$col = imagecolorallocate($im,$rgb_out[0],$rgb_out[1],$rgb_out[2]);
imagesetpixel($im,$x,$y,$col);
}
}
/*
Test output
*/
imagejpeg($im,'colortable.jpg');
echo '<img src="colortable.jpg">';
?>
----
Server IP: 81.94.227.69
Probable Submitter: 159.148.13.2 (proxied: 159.148.13.35)
----
Manual Page -- http://www.php.net/manual/en/function.imagesetpixel.php
Edit -- https://master.php.net/note/edit/74488
Del: integrated -- https://master.php.net/note/delete/74488/integrated
Del: useless -- https://master.php.net/note/delete/74488/useless
Del: bad code -- https://master.php.net/note/delete/74488/bad+code
Del: spam -- https://master.php.net/note/delete/74488/spam
Del: non-english -- https://master.php.net/note/delete/74488/non-english
Del: in docs -- https://master.php.net/note/delete/74488/in+docs
Del: other reasons-- https://master.php.net/note/delete/74488
Reject -- https://master.php.net/note/reject/74488
Search -- https://master.php.net/manage/user-notes.php