|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Created on: <16-Mar-2003 17:56:32 kk> 00004 // 00005 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00006 // SOFTWARE NAME: eZ Publish 00007 // SOFTWARE RELEASE: 4.0.x 00008 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS 00009 // SOFTWARE LICENSE: GNU General Public License v2.0 00010 // NOTICE: > 00011 // This program is free software; you can redistribute it and/or 00012 // modify it under the terms of version 2.0 of the GNU General 00013 // Public License as published by the Free Software Foundation. 00014 // 00015 // This program is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU General Public License for more details. 00019 // 00020 // You should have received a copy of version 2.0 of the GNU General 00021 // Public License along with this program; if not, write to the Free 00022 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00023 // MA 02110-1301, USA. 00024 // 00025 // 00026 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00027 // 00028 00029 /*! \file eztemplateautoload.php 00030 */ 00031 00032 /*! 00033 \defgroup eZMath eZ Math library 00034 */ 00035 00036 /*! 00037 \class eZMath ezmath.php 00038 \brief eZMath provide a simple math library for common math operations 00039 */ 00040 00041 class eZMath 00042 { 00043 /*! 00044 Constructor 00045 */ 00046 function eZMath() 00047 { 00048 } 00049 00050 /*! 00051 \static 00052 00053 Normalize RGB color array to 0..1 range 00054 00055 \param array to normalize 00056 00057 \return normalized array 00058 */ 00059 static function normalizeColorArray( $array ) 00060 { 00061 foreach ( array_keys( $array ) as $key ) 00062 { 00063 $array[$key] = (float)$array[$key]/256; 00064 } 00065 00066 return $array; 00067 } 00068 00069 /*! 00070 \static 00071 00072 Convert RGB to CMYK, Normalized values, between 0 and 1 00073 00074 \param RGB array 00075 \return CMYK array 00076 */ 00077 static function rgbToCMYK( $rgbArray ) 00078 { 00079 $cya = 1 - min( 1, max( (float)$rgbArray['r'], 0 ) ); 00080 $mag = 1 - min( 1, max( (float)$rgbArray['g'], 0 ) ); 00081 $yel = 1 - min( 1, max( (float)$rgbArray['b'], 0 ) ); 00082 00083 $min = min( $cya, $mag, $yel ); 00084 if ( 1 - $min == 0 ) 00085 { 00086 return array( 'c' => 1, 00087 'm' => 1, 00088 'y' => 1, 00089 'k' => 0 ); 00090 } 00091 00092 return array( 'c' => ( $cya - $min ) / ( 1 - $min ), 00093 'm' => ( $mag - $min ) / ( 1 - $min ), 00094 'y' => ( $yel - $min ) / ( 1 - $min ), 00095 'k' => $min ); 00096 } 00097 00098 /*! 00099 \static 00100 00101 Convert rgb to CMYK 00102 00103 \param R 00104 \param B 00105 \param G 00106 00107 \return CMYK return array 00108 */ 00109 static function rgbToCMYK2( $r, $g, $b ) 00110 { 00111 return eZMath::rgbToCMYK( array( 'r' => $r, 00112 'g' => $g, 00113 'b' => $b ) ); 00114 } 00115 } 00116 ?>