Skip to main content
Module

x/imagescript/ImageScript.js>Image

zero-dependency JavaScript image manipulation
Extremely Popular
Go to Latest
class Image
import { Image } from "https://deno.land/x/imagescript@1.2.15/ImageScript.js";

Represents an image; provides utility functions

Constructors

new
Image(width, height)

Creates a new image with the given dimensions

Properties

readonly
height

The images height

readonly
width

The images width

Methods

__apply__(image)
__crop__(
x,
y,
width,
height,
)
__fast_box__(
x,
y,
width,
height,
color,
)
__resize__(
width,
height,
mode?,
)
__set_channel_value__(
value,
absolute,
offset,
)
__set_pixel__(
x,
y,
pixelColor,
)

Gets the average color of the image

blue(saturation, absolute?)

Sets the blue channels saturation

Clones the current image

composite(
source,
x?,
y?,
)

Composites (overlays) the source onto this image at the specified coordinates

contain(
width,
height,
mode?,
)

Resizes the image so it is contained in the given bounding box. Can return an image with one axis smaller than the given bounding box.

cover(
width,
height,
mode?,
)

Resizes the image so it covers the given bounding box, cropping the overflowing edges. Always returns the exact dimensions of the bounding box.

crop(
x,
y,
width,
height,
)

Crops an image to the specified dimensions

cropCircle(max?, feathering?)

Crops the image into a circle

dominantColor(
ignoreBlack?,
ignoreWhite?,
bwThreshold?,
)

Gets the images dominant color

drawBox(
x,
y,
width,
height,
color,
)

Draws a box at the specified coordinates

drawCircle(
x,
y,
radius,
color,
)

Draws a circle at the specified coordinates with the specified radius

encode(compression?)

Encodes the image into a PNG

encodeJPEG(quality?)

Encodes the image into a JPEG

fill(color)

Fills the image data with the supplied color

fisheye(radius?)
fit(
width,
height,
mode?,
)

Resizes the image so it is contained in the given bounding box, placing it in the center of the given bounding box. Always returns the exact dimensions of the bounding box.

Gets the pixel color at the specified position

getRGBAAt(x, y)

Gets the pixel color at the specified position

green(saturation, absolute?)

Sets the green channels saturation

hueShift(degrees)

Shifts the images hue

Inverts the images colors

Inverts the images hue

Inverts the images saturation

Inverts the images value (lightness)

Yields an [x,y,color] array for every pixel in the image

lightness(value, absolute?)

Sets the brightness of the image

opacity(opacity, absolute?)

Sets the images opacity

red(saturation, absolute?)

Sets the red channels saturation

resize(
width,
height,
mode?,
)

Resizes the image to the given dimensions. Use Image.RESIZE_AUTO as either width or height to automatically preserve the aspect ratio.

rotate(angle, resize?)

Rotates the image the given amount of degrees

roundCorners(radius?)

Rounds the images corners

saturation(value, absolute?)

Sets the saturation of the image

scale(factor, mode?)

Resizes the image by the given factor

setPixelAt(
x,
y,
pixelColor,
)

Sets the pixel color for the specified position

Yields an [x,y] array for every pixel in the image

Static Properties

readonly
__out_of_bounds__
readonly
RESIZE_AUTO

Used for automatically preserving an images aspect ratio when resizing.

readonly
RESIZE_NEAREST_NEIGHBOR

Use Nearest-neighbor resizing.

readonly
SVG_MODE_HEIGHT

Scale the SVG to fit the given height. For use with Image.renderSVG

readonly
SVG_MODE_SCALE

Scale the SVG by the given amount. For use with Image.renderSVG

readonly
SVG_MODE_WIDTH

Scale the SVG to fit the given width. For use with Image.renderSVG

Static Methods

__gradient__(startColor, endColor)
colorToRGB(color)

Converts a color value to an array of RGB values (ignoring the colors alpha)

Converts a color value to an array of RGBA values

decode(data)

Decodes an image (PNG, JPEG or TIFF)

gradient(colors)

Creates a multi-point gradient generator

hslaToColor(
h,
s,
l,
a,
)

Converts HSLA colors to RGBA colors

hslToColor(
h,
s,
l,
)

Converts HSL colors to RGBA colors (assuming an opacity of 255)

renderSVG(
svg,
size?,
mode?,
)

Creates a new image from the given SVG

renderText(
font,
scale,
text,
color?,
layout?,
)

Creates a new image containing the rendered text.

rgbaToColor(
r,
g,
b,
a,
)

Converts RGBA components to an RGBA value

rgbaToHSLA(
r,
g,
b,
a,
)

Converts an RGBA value to an array of HSLA values

rgbToColor(
r,
g,
b,
)

Converts RGB components to an RGBA value (assuming alpha = 255)