note 79996 added to ref.image

From: Date: Sun, 23 Dec 2007 11:19:42 +0000
Subject: note 79996 added to ref.image
Groups: php.notes 
Request: Send a blank email to php-notes+get-133892@lists.php.net to get a copy of this message
<?php /** HSL/RGB conversion functions very useful for a lot of applications **/ function RBGtoHSL ( $R, $G, $B ) { $var_R = ( $R / 255 ); $var_G = ( $G / 255 ); $var_B = ( $B / 255 ); $var_Min = min( $var_R, $var_G, $var_B ) $var_Max = max( $var_R, $var_G, $var_B ) $del_Max = $var_Max - $var_Min $L = ( $var_Max + $var_Min ) / 2; if ( $del_Max == 0 ) { $H = 0 $S = 0 } else { if ( $L < 0.5 ) { $S = $del_Max / ( $var_Max + $var_Min ); } else { $S = $del_Max / ( 2 - $var_Max - $var_Min ); } $del_R = ( ( ( $var_Max - $var_R ) / 6 ) + ( $del_Max / 2 ) ) / $del_Max; $del_G = ( ( ( $var_Max - $var_G ) / 6 ) + ( $del_Max / 2 ) ) / $del_Max; $del_B = ( ( ( $var_Max - $var_B ) / 6 ) + ( $del_Max / 2 ) ) / $del_Max; if ( $var_R == $var_Max ) { $H = $del_B - $del_G; } else if ( $var_G == $var_Max ) { $H = ( 1 / 3 ) + $del_R - $del_B; } else if ( $var_B == $var_Max ) { $H = ( 2 / 3 ) + $del_G - $del_R; } if ( $H < 0 ) { $H += 1; } if ( $H > 1 ) { $H -= 1 } } return array( $H, $S, $L ); } function HuetoRGB( $v1, $v2, $vH ) { if ( $vH < 0 ) { $vH += 1; } if ( $vH > 1 ) { $vH -= 1; } if ( ( 6 * $vH ) < 1 ) { return ( $v1 + ( $v2 - $v1 ) * 6 * $vH ); } if ( ( 2 * $vH ) < 1 ) { return ( $v2 ); } if ( ( 3 * $vH ) < 2 ) { return ( $v1 + ( $v2 - $v1 ) * ( ( 2 / 3 ) - $vH ) * 6 ); } return ( $v1 ) } function HSLtoRGB ( $H, $S, $L ) { if ( $S == 0 ) { $R = $L * 255; $G = $L * 255; $B = $L * 255; } else { if ( $L < 0.5 ) { $var_2 = $L * ( 1 + $S ); } else { $var_2 = ( $L + $S ) - ( $S * $L ); } $var_1 = 2 * $L - $var_2; $R = 255 * HuetoRGB( $var_1, $var_2, $H + ( 1 / 3 ) ); $G = 255 * HuetoRGB( $var_1, $var_2, $H ); $B = 255 * HuetoRGB( $var_1, $var_2, $H - ( 1 / 3 ) ); } return array( $R, $G, $B ); } function distance ( $R1, $G1, $B1, $R2, $G2, $B2 ) { $result = sqrt ( ( $R1 - $R2 )*( $R1 - $R2 ) + ( $G1 - $G2 )*( $G1 - $G2 ) + ( $B1 - $B2 )*( $B1 - $B2 ) ); return ( $result ); } ?> ---- Server IP: 217.174.196.197 Probable Submitter: 86.70.5.123 ---- Manual Page -- http://www.php.net/manual/en/ref.image.php Edit -- https://master.php.net/note/edit/79996 Del: integrated -- https://master.php.net/note/delete/79996/integrated Del: useless -- https://master.php.net/note/delete/79996/useless Del: bad code -- https://master.php.net/note/delete/79996/bad+code Del: spam -- https://master.php.net/note/delete/79996/spam Del: non-english -- https://master.php.net/note/delete/79996/non-english Del: in docs -- https://master.php.net/note/delete/79996/in+docs Del: other reasons-- https://master.php.net/note/delete/79996 Reject -- https://master.php.net/note/reject/79996 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#133892) next »