Image_Color
[ class tree: Image_Color ] [ index: Image_Color ] [ all elements ]

Class: Image_Color

Source Location: /Image_Color-1.0.4/Color.php

Class Overview


Image_Color handles color conversion and mixing.


Author(s):

Version:

  • Release: 0.1.2

Copyright:

  • 2003-2005 The PHP Group

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 64]
Image_Color handles color conversion and mixing.

The class is quick, simple to use, and does its job fairly well but it's got some code smells:

  • Call setColors() for some functions but not others.
  • Different functions expect different color formats. setColors() only accepts hex while allocateColor() will accept named or hex (provided the hex ones start with the # character).
  • Some conversions go in only one direction, ie HSV->RGB but no RGB->HSV.
I'm going to try to straighten out some of this but I'll be hard to do so without breaking backwards compatibility.



[ Top ]


Class Variables

$color1 = array()

[line 72]

First color that the class handles for ranges and mixes.

Type:   array


[ Top ]

$color2 = array()

[line 80]

Second color that the class handles for ranges and mixes.

Type:   array


[ Top ]



Method Detail

allocateColor   [line 473]

resource allocateColor( &$img, string|array $color, resource $img)

Allocates a color in the given image.

User defined color specifications get translated into an array of RGB values.

  • Return: Image color handle.
  • Access: public
  • Uses: ImageColorAllocate() - to allocate the color.
  • Uses: Image_Color::color2RGB() - to parse the color into RGB values.

Parameters:

resource   $img   —  Image handle
string|array   $color   —  Name or hex string or an RGB array.
   &$img   — 

[ Top ]

changeLightness   [line 227]

void changeLightness( [integer $degree = 10])

Change the lightness of the class's two colors.

Parameters:

integer   $degree   —  The degree of the change. Positive values lighten the color while negative values will darken it.

[ Top ]

color2RGB   [line 493]

array color2RGB( string $color)

Convert a named or hex color string to an RGB array. If the color begins with the # character it will be treated as a hex value. Everything else will be treated as a named color. If the named color is not known, black will be returned.

Parameters:

string   $color   — 

[ Top ]

getRange   [line 163]

array getRange( [integer $degrees = 2])

Get the range of colors between the class's two colors, given a degree.
  • Return: Returns an array of hex strings, one element for each color.
  • Author: Jason Lotito <jason@lehighweb.com>
  • Todo: Allow for degrees for individual parts of the colors.
  • Access: public

Parameters:

integer   $degrees   —  How large a 'step' we should take between the colors.

[ Top ]

getTextColor   [line 276]

string getTextColor( string $color, [string $light = '#FFFFFF'], [string $dark = '#000000'])

Determine if a light or dark text color would be more readable on a background of a given color. This is determined by the G(reen) value of RGB. You can change the dark and the light colors from their default black and white.
  • Return: The light or dark value which would make the text most readable.
  • Author: Jason Lotito <jason@lehighweb.com>
  • Access: public

Parameters:

string   $color   —  The hex color to analyze
string   $light   —  The light color value to return if we should have light text.
string   $dark   —  The dark color value to return if we should have dark text.

[ Top ]

hex2rgb   [line 362]

array hex2rgb( string $hex)

Convert a hex color string into an RGB array. An extra fourth element will be returned with the original hex value.

Parameters:

string   $hex   —  Hex color string.

[ Top ]

hsv2hex   [line 402]

string hsv2hex( integer $h, integer $s, integer $v)

Convert HSV (Hue, Saturation, Brightness) to a hex color string.

Originally written by Jurgen Schwietering. Integrated into the class by Jason Lotito.


Parameters:

integer   $h   —  Hue
integer   $s   —  Saturation
integer   $v   —  Brightness

[ Top ]

hsv2rgb   [line 382]

array hsv2rgb( integer $h, integer $s, integer $v)

Convert an HSV (Hue, Saturation, Brightness) value to RGB.

Parameters:

integer   $h   —  Hue
integer   $s   —  Saturation
integer   $v   —  Brightness

[ Top ]

mixColors   [line 104]

string mixColors( [string $col1 = false], [string $col2 = false])

Mix two colors together by finding their average. If the colors are not passed as parameters, the class's colors will be mixed instead.
  • Return: The mixed color.
  • Author: Jason Lotito <jason@lehighweb.com>
  • Access: public
  • Uses: _setColors() - to assign the colors if any are passed to the class.

Parameters:

string   $col1   —  The first color you want to mix
string   $col2   —  The second color you want to mix

[ Top ]

namedColor2RGB   [line 517]

array namedColor2RGB( string $color)

Convert a named color to an RGB array. If the color is unknown black is returned.

Parameters:

string   $color   —  Case insensitive color name.

[ Top ]

percentageColor2RGB   [line 683]

array percentageColor2RGB( string $color)

Convert an RGB percentage string into an RGB array.
  • Return: RGB color array.
  • Access: public

Parameters:

string   $color   —  Percentage color string like "50%,20%,100%".

[ Top ]

rgb2hex   [line 345]

string rgb2hex( array $color)

Convert an RGB array to a hex string.

Parameters:

array   $color   —  3 element RGB array.

[ Top ]

setColors   [line 147]

void setColors( string $col1, string $col2)

Set the two colors this class uses for mixing and ranges.

Parameters:

string   $col1   —  The first color in hex format
string   $col2   —  The second color in hex format

[ Top ]

setWebSafe   [line 133]

void setWebSafe( [boolean $bool = true])

Determines whether colors the returned by this class will be rounded to the nearest web safe value.

Parameters:

boolean   $bool   —  Indicates if colors should be limited to the websafe pallet.

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:37:15 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.