Namespace Graphics
Color and graphic utilties for SalsaScript.
Include: /salsa/common/Graphics.sjs
Constructor Attributes | Constructor Name and Description |
---|---|
Method Attributes | Method Name and Description |
---|---|
<static> |
Graphics.brightenColor(color, scale)
Brighten the passed color by scaling it to white.
|
<static> |
Graphics.colorToHexString(color)
Convert a W3C CSS color name to its corresponding six character
hex string.
|
<static> |
Graphics.darkenColor(color, scale)
Darken the passed color by scaling it to black
|
<static> |
Graphics.fontImageLink(link)
Generate a link to a dynamically created text png using
fontimage.jsp |
<static> |
Graphics.getImageUrl(image_path, opts)
Generate a link for a resized image, using the
imagine.sjs
system. |
<static> |
Graphics.gradientLink(grad)
Generate a link to a dynamically created gradient png using
gradient.jsp |
<static> |
Graphics.hexStringToRgb(hexstr)
Convert a CSS hexadecimal color string to an array of its
red, green and blue components in decimal.
|
<static> |
Graphics.hslToRgb(h, s, l)
Convert a Hue-Saturation-Lightness color to its equivalent
Red-Green-Blue definition.
|
<static> |
Graphics.rgbToHexString(r, g, b)
Convert three numbers describing a color's red, green and blue
components to a CSS hexadecimal color string.
|
<static> |
Graphics.rgbToHsl(r, g, b)
Convert a Red-Green-Blue color to its equivalent
Hue-Saturation-Lightness definition.
|
<static> |
Graphics.scaleColor(color, scale)
Brighten or darken a color by scaling it linearly towards white
or black.
|
Method Detail
<static>
{String}
Graphics.brightenColor(color, scale)
Brighten the passed color by scaling it to white.
- Parameters:
- {String} color
- A CSS color string.
- {Number} scale
- A number between 0 and 1 (inclusive) where
- 0 represents the original color
- 1 represents white
- a number inbetween represents the distance between the original and white
- Returns:
- {String} A hexadecimal CSS color string
- See:
- Graphics.scaleColor
<static>
Graphics.colorToHexString(color)
Convert a W3C CSS color name to its corresponding six character
hex string.
- Parameters:
- {String} color
- The color name to convert
- Returns:
- A six character hex color string if the color is found,
otherwise the passed value of
color
<static>
{String}
Graphics.darkenColor(color, scale)
Darken the passed color by scaling it to black
- Parameters:
- {String} color
- A CSS color string.
- {Number} scale
- A number between 0 and 1 (inclusive) where
- 0 represents black
- 1 represents the original color
- A number inbetween represents the distance between the original and black
- Returns:
- {String} A hexadecimal CSS color string
- See:
- Graphics.scaleColor
<static>
{String}
Graphics.fontImageLink(link)
Generate a link to a dynamically created text png using
fontimage.jsp
- Parameters:
- {Object|Array} link
- An object describing the font image or an array of objects describing one or more font images to stack in a single png
- text Optional, Default: "Hello, world!"
- The text to print
- size Optional, Default: 24
- The font size
- color Optional, Default: "black"
- The color of the font
- background Optional, Default: "white"
- The background color of the font
- font Optional, Default: "Chunkfive.ttf"
- The custom font file to use
link {...}
- Returns:
- {String} A relative link to the generated image in the form
/fontimage.jsp?text=...
<static>
{String}
Graphics.getImageUrl(image_path, opts)
Generate a link for a resized image, using the
imagine.sjs
system.
If the path given is remote or no resizing options are provided, the
same path is returned as the result.
- Parameters:
- {String} image_path
- A path to an image accessible by this organization (e.g., a filename or relative path under "images/")
- {Object} opts
- Parameters for the resizing (optional)
- width Optional
- The requested width of the image (may be smaller)
- height Optional
- The requested height of the image (may be smaller)
- type Optional
- Type may be 'ex', 'le', 'al', or 'co'. The default
(if it's missing) is 'ex'.
- if type is 'ex', an exact scaled image is returned. This image will have a width and height specified. This is the only case in which width and height are not both required. If only one is provided, a scaled image with the same aspect ratio as the original will be returned.
- if type is 'le', the image will be shrunk to fit within the requested dimensions without clipping, but will be left alone if it is already smaller than them.
- if type is 'al', the image will be either shrunk or expanded so that it just fits in the requested dimensions without clipping.
- if type is 'co', the image will be shrunk or expanded so that it best fills the requested dimensions, usually clipping two sides.
- xoffset Optional
- The x-coordinate of the top-left corner of the image region to use (0 by default)
- yoffset Optional
- The y-coordinate of the top-left corner of the image region to use (0 by default)
- xspan Optional
- The width of the image region to use (the image width by default)
- yspan Optional
- The height of the image region to use (the image height by default)
opts {...}
- Returns:
- {String} an absolute link to the scaled image, as produced by the Imagine system.
<static>
{String}
Graphics.gradientLink(grad)
Generate a link to a dynamically created gradient png using
gradient.jsp
- Parameters:
- {Object|Array} grad
- An object describing the gradient or an array of objects describing one or more gradients and files to stack in a single png
- height Optional, Default: 100
- The height of the gradient
- width Optional, Default: 100
- The width of the gradient
- color1 Optional, Default: "white"
- The first color
- color2 Optional, Default: "black"
- The second color
- xStart Optional, Default: 0
- The x coordinate of the first color point
- yStart Optional, Default: 0
- The y coordinate of the first color point
- xEnd Optional, Default: 0
- The x coordinate of the second color point
- yEnd Optional, Default: grad.height
- The y coordinate of the second color point
- cyclic Optional, Default: false
- Indicates whether the gradient should repeat itself
- file Optional
- The name of the static png to merge into the image
- fileposition Optional, Default: position of file in array
- The position of the file in the image stack
grad {...}
- Returns:
- {String} A relative link to the generated image in the form
/gradient.jsp?height=...
<static>
{Array}
Graphics.hexStringToRgb(hexstr)
Convert a CSS hexadecimal color string to an array of its
red, green and blue components in decimal.
- Parameters:
- {String} hexstr
- The hexidecimal color string
- Returns:
- {Array} An array of three numbers defining the colors
[Red, Green, Blue]
components.
<static>
{Array}
Graphics.hslToRgb(h, s, l)
Convert a Hue-Saturation-Lightness color to its equivalent
Red-Green-Blue definition.
- Parameters:
- {Number|Array} h
- An number describing the color's hue
component or an array of 3 numbers
describing its
[Hue, Saturation, Lightness]
components. - {Number} s
- A number describing the color's saturation component.
- {Number} l
- A number describing the color's lightness component.
- Returns:
- {Array} An array of three numbers describing a color's red, green and blue levels.
- See:
- Graphics.rgbToHsl
<static>
{String}
Graphics.rgbToHexString(r, g, b)
Convert three numbers describing a color's red, green and blue
components to a CSS hexadecimal color string.
- Parameters:
- {Number|Array} r
- An number describing the color's red
component or an array of 3 numbers
describing its
[Red, Green, Blue]
components. - {Number} g
- A number describing the color's green component.
- {Number} b
- A number describing the color's blue component.
- Returns:
- {String} A 6 character hexadecimal CSS color string.
<static>
{Array}
Graphics.rgbToHsl(r, g, b)
Convert a Red-Green-Blue color to its equivalent
Hue-Saturation-Lightness definition.
- Parameters:
- {Number|Array} r
- An number describing the color's red
component or an array of 3 numbers
describing its
[Red, Green, Blue]
components. - {Number} g
- A number describing the color's green component.
- {Number} b
- A number describing the color's blue component.
- Returns:
- {Array} An array of three numbers describing a color's hue, saturation and lightness levels.
- See:
- Graphics.hslToRgb
<static>
{String}
Graphics.scaleColor(color, scale)
Brighten or darken a color by scaling it linearly towards white
or black.
Example color1
= FF0000
Example color2
= ff7f7f
Example color3
= 7f0000
color1 = "ff0000"; //red color2 = Graphics.scaleColor(color1, .75); //A color halfway between red and white color3 = Graphics.scaleColor(color1, .25); //A color halfway between red and black
- Parameters:
- {String} color
- A CSS color string
- {Number} scale
- A number between 0 and 1 (inclusive) determining
the brightness of the color to return where:
- 0 returns black
- 0.5 returns the original color
- 1 returns white
- (0, .5) returns a color that is
n
/.5 between between the original color and black. - (.5, 1) returns a color that is (.5 -
n
) * 2 between between the original color and white.
- Returns:
- {String} A hexadecimal CSS string representing the scaled color.