source-class-Com.Tecnick.Color.Model.Gray

It appears that you are using AdBlocking software. The cost of running this website is covered by advertisements. If you like it please feel free to a small amount of money to secure the future of this website.
  1: <?php
  2: /**
  3:  * Gray.php
  4:  *
  5:  * @since       2015-02-21
  6:  * @category    Library
  7:  * @package     Color
  8:  * @author      Nicola Asuni <info@tecnick.com>
  9:  * @copyright   2015-2015 Nicola Asuni - Tecnick.com LTD
 10:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
 11:  * @link        https://github.com/tecnickcom/tc-lib-color
 12:  *
 13:  * This file is part of tc-lib-color software library.
 14:  */
 15: 
 16: namespace Com\Tecnick\Color\Model;
 17: 
 18: /**
 19:  * Com\Tecnick\Color\Model\Gray
 20:  *
 21:  * Gray Color Model class
 22:  *
 23:  * @since       2015-02-21
 24:  * @category    Library
 25:  * @package     Color
 26:  * @author      Nicola Asuni <info@tecnick.com>
 27:  * @copyright   2015-2015 Nicola Asuni - Tecnick.com LTD
 28:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
 29:  * @link        https://github.com/tecnickcom/tc-lib-color
 30:  */
 31: class Gray extends \Com\Tecnick\Color\Model implements \Com\Tecnick\Color\Model\Template
 32: {
 33:     /**
 34:      * Color Model type
 35:      *
 36:      * @var string
 37:      */
 38:     protected $type = 'GRAY';
 39: 
 40:     /**
 41:      * Value of the Gray color component [0..1]
 42:      *
 43:      * @var float
 44:      */
 45:     protected $cmp_gray = 0.0;
 46: 
 47:     /**
 48:      * Get an array with all color components
 49:      *
 50:      * @return array with keys ('G', 'A')
 51:      */
 52:     public function getArray()
 53:     {
 54:         return array(
 55:             'G' => $this->cmp_gray,
 56:             'A' => $this->cmp_alpha
 57:         );
 58:     }
 59: 
 60:     /**
 61:      * Get an array with color components values normalized between 0 and $max.
 62:      * NOTE: the alpha and other fraction component values are kept in the [0..1] range.
 63:      *
 64:      * @param int $max Maximum value to return (reference value)
 65:      *
 66:      * @return array with keys ('G', 'A')
 67:      */
 68:     public function getNormalizedArray($max)
 69:     {
 70:         return array(
 71:             'G' => $this->getNormalizedValue($this->cmp_gray, $max),
 72:             'A' => $this->cmp_alpha
 73:         );
 74:     }
 75: 
 76:     /**
 77:      * Get the CSS representation of the color: rgba(R, G, B, A)
 78:      * NOTE: Supported since CSS3 and above.
 79:      *       Use getHexadecimalColor() for CSS1 and CSS2
 80:      *
 81:      * @return string
 82:      */
 83:     public function getCssColor()
 84:     {
 85:         return 'rgba('
 86:             .$this->getNormalizedValue($this->cmp_gray, 100).'%,'
 87:             .$this->getNormalizedValue($this->cmp_gray, 100).'%,'
 88:             .$this->getNormalizedValue($this->cmp_gray, 100).'%,'
 89:             .$this->cmp_alpha
 90:             .')';
 91:     }
 92: 
 93:     /**
 94:      * Get the color format used in Acrobat JavaScript
 95:      * NOTE: the alpha channel is omitted from this representation unless is 0 = transparent
 96:      *
 97:      * @return string
 98:      */
 99:     public function getJsPdfColor()
100:     {
101:         if ($this->cmp_alpha == 0) {
102:             return '["T"]'; // transparent color
103:         }
104:         return sprintf('["G",%F]', $this->cmp_gray);
105:     }
106: 
107:     /**
108:      * Get a space separated string with color component values.
109:      *
110:      * @return string
111:      */
112:     public function getComponentsString()
113:     {
114:         return sprintf('%F', $this->cmp_gray);
115:     }
116: 
117:     /**
118:      * Get the color components format used in PDF documents (G)
119:      * NOTE: the alpha channel is omitted
120:      *
121:      * @param bool $stroke True for stroking (lines, drawing) and false for non-stroking (text and area filling).
122:      *
123:      * @return string
124:      */
125:     public function getPdfColor($stroke = false)
126:     {
127:         $mode = 'g';
128:         if ($stroke) {
129:             $mode = strtoupper($mode);
130:         }
131:         return $this->getComponentsString().' '.$mode."\n";
132:     }
133: 
134:     /**
135:      * Get an array with Gray color components
136:      *
137:      * @return array with keys ('gray')
138:      */
139:     public function toGrayArray()
140:     {
141:         return array(
142:             'gray'  => $this->cmp_gray,
143:             'alpha' => $this->cmp_alpha
144:         );
145:     }
146: 
147:     /**
148:      * Get an array with RGB color components
149:      *
150:      * @return array with keys ('red', 'green', 'blue', 'alpha')
151:      */
152:     public function toRgbArray()
153:     {
154:         return array(
155:             'red'   => $this->cmp_gray,
156:             'green' => $this->cmp_gray,
157:             'blue'  => $this->cmp_gray,
158:             'alpha' => $this->cmp_alpha
159:         );
160:     }
161: 
162:     /**
163:      * Get an array with HSL color components
164:      *
165:      * @return array with keys ('hue', 'saturation', 'lightness', 'alpha')
166:      */
167:     public function toHslArray()
168:     {
169:         return array(
170:             'hue'        => 0,
171:             'saturation' => 0,
172:             'lightness'  => $this->cmp_gray,
173:             'alpha'      => $this->cmp_alpha
174:         );
175:     }
176: 
177:     /**
178:      * Get an array with CMYK color components
179:      *
180:      * @return array with keys ('cyan', 'magenta', 'yellow', 'key', 'alpha')
181:      */
182:     public function toCmykArray()
183:     {
184:         return array(
185:             'cyan'    => 0,
186:             'magenta' => 0,
187:             'yellow'  => 0,
188:             'key'     => $this->cmp_gray,
189:             'alpha'   => $this->cmp_alpha
190:         );
191:     }
192: 
193:     /**
194:      * Invert the color
195:      */
196:     public function invertColor()
197:     {
198:         $this->cmp_gray = (1 - $this->cmp_gray);
199:         return $this;
200:     }
201: }
202: 
 

© 2004-2017 – Nicola Asuni - Tecnick.com - All rights reserved.
about - disclaimer - privacy