image library

The image library aims to provide server-side programs the ability to load, manipulate, and save various image file formats.

Classes

Animation
Stores multiple images, most often as the frames of an animation.
BitmapFont
A bitmap font that can be used with drawString and drawChar functions. If you want use own fonts following with this steps: 1. Get your .ttf file - important is to select file with specific style which you want for example when you download .ttf file from google fonts: select file from /static folder example name: Roboto-Black.ttf 2. Convert ttf file to fnt zip with page: https://ttf2fnt.com/ 3. Create dart file with code: void main() { String fileName = 'YourFontName-Style.zip'; // your file has to be in the same folder as this program File file = File('$fileName'); List
BitmapFontCharacter
A single character in a BitmapFont.
BitUtility
BmpDecoder
BmpEncoder
Encode a BMP image.
Color
Image pixel colors are instantiated as an int object rather than an instance of the Color class in order to reduce object allocations. Image pixels are stored in 32-bit RGBA format (8 bits per channel). Internally in dart, this will be stored in a "small integer" on 64-bit machines, or a "medium integer" on 32-bit machines. In Javascript, this will be stored in a 64-bit double.
DecodeInfo
Provides information about the image being decoded.
Decoder
Base class for image format decoders.
DibDecoder
Encoder
Base class for image format encoders.
ExifAsciiValue
ExifByteValue
ExifData
ExifDoubleValue
ExifEntry
ExifIFD
ExifIFDContainer
ExifLongValue
ExifRationalValue
ExifSByteValue
ExifShortValue
ExifSingleValue
ExifSLongValue
ExifSRationalValue
ExifSShortValue
ExifTag
ExifUndefinedValue
ExifValue
ExrAttribute
ExrB44Compressor
ExrChannel
ExrCompressor
ExrDecoder
Decode an OpenEXR formatted image.
ExrHufDec
ExrHuffman
ExrImage
ExrPart
ExrPizCompressor
Wavelet compression
ExrPxr24Compressor
ExrRleCompressor
ExrWavelet
ExrZipCompressor
GifColorMap
GifDecoder
A decoder for the GIF image format. This supports both single frame and animated GIF files, and transparency.
GifEncoder
GifImageDesc
GifInfo
Half
A 16-bit floating-point number, used by high-dynamic-range image formats as a more efficient storage for floating-point values that don't require full 32-bit precision. A list of Half floats can be stored in a Uint16List, and converted to a double using the HalfToDouble static method.
HdrImage
A high dynamic range RGBA image stored in 16-bit or 32-bit floating-point channels.
HdrSlice
A slice is the data for an image framebuffer for a single channel.
IcoDecoder
IcoInfo
IcoInfoImage
Image
An image buffer where pixels are encoded into 32-bit unsigned ints (Uint32).
InputBuffer
A buffer that can be read as a stream of bytes.
Jpeg
JpegAdobe
JpegComponent
JpegData
JpegDecoder
Decode a jpeg encoded image.
JpegEncoder
Encode an image to the JPEG format.
JpegFrame
JpegInfo
JpegJfif
JpegScan
LzwDecoder
NeuralQuantizer
Compute a color map with a given number of colors that best represents the given image.
OutputBuffer
PngDecoder
Decode a PNG encoded image.
PngEncoder
Encode an image to the PNG format.
PngFrame
PngInfo
Point
2-dimensional point
PsdBevelEffect
PsdBlendingRanges
PsdChannel
PsdDecoder
Decode a Photoshop PSD image.
PsdDropShadowEffect
PsdEffect
PsdImage
PsdImageResource
PsdInnerGlowEffect
PsdInnerShadowEffect
PsdLayer
PsdLayerAdditionalData
PsdLayerData
PsdLayerSectionDivider
PsdMask
PsdOuterGlowEffect
PsdSolidFillEffect
PvrtcColorBoundingBox<Color extends PvrtcColorRgbCore<Color>>
PvrtcColorRgb
PvrtcColorRgba
PvrtcColorRgbCore<T>
PvrtcDecoder
PvrtcEncoder
PvrtcPacket
Rational
SeparableKernel
A kernel object to use with separableConvolution filtering.
TgaDecoder
Decode a TGA image. This only supports the 24-bit uncompressed format.
TgaEncoder
Encode a TGA image. This only supports the 24-bit uncompressed format.
TgaInfo
TiffBitReader
TiffDecoder
TiffEncoder
Encode a TIFF image.
TiffEntry
TiffFaxDecoder
TiffImage
TiffInfo
Trim
VP8
VP8BandProbas
VP8BitReader
VP8Filter
VP8FilterHeader
VP8FInfo
VP8FrameHeader
VP8L
VP8LBitReader
VP8LColorCache
VP8LTransform
VP8MB
VP8MBData
VP8PictureHeader
VP8Proba
VP8QuantMatrix
VP8Random
VP8SegmentHeader
VP8TopSamples
WebPAlpha
WebPDecoder
Decode a WebP formatted image. This supports lossless (vp8l), lossy (vp8), lossy+alpha, and animated WebP images.
WebPEncoder
Encode an image to the PNG format.
WebPFilters
WebPFrame
WebPInfo

Constants

ExifTagNameToID → const Map<String, int>
ExifValueTypeSize → const List<int>
ExifValueTypeString → const List<String>

Properties

arial_14 BitmapFont
14px Arial font for use with drawString and drawChar.
final
arial_24 BitmapFont
24px Arial font for use with drawString and drawChar.
final
arial_48 BitmapFont
48px Arial font for use with drawString and drawChar.
final
ExifGpsTags Map<int, ExifTag>
final
ExifImageTags Map<int, ExifTag>
final
ExifInteropTags Map<int, ExifTag>
final

Functions

adjustColor(Image src, {int? blacks, int? whites, int? mids, num? contrast, num? saturation, num? brightness, num? gamma, num? exposure, num? hue, num? amount}) Image
Adjust the color of the src image using various color transformations.
alphaBlendColors(int dst, int src, [int fraction = 0xff]) int
Returns a new color of src alpha-blended onto dst. The opacity of src is additionally scaled by fraction / 255.
bakeOrientation(Image image) Image
If image has an orientation value in its exif data, this will rotate the image so that it physically matches its orientation. This can be used to bake the orientation of the image for image formats that don't support exif data.
brightness(Image? src, int brightness) Image?
Set the brightness level for the image src. brightness is an offset that is added to the red, green, and blue channels of every pixel.
bumpToNormal(Image src, {num strength = 2.0}) Image
Generate a normal map from a heightfield bump image.
clipLine(List<int> line, List<int> rect) bool
Clip a line to a rectangle using the Cohen–Sutherland clipping algorithm. line is a list of 4 ints <x1, y1, x2, y2>. rect is a list of 4 ints <x1, y1, x2, y2>. Results are stored in line. If line falls completely outside of rect, false is returned, otherwise true is returned.
cmykToRgb(num c, num m, num y, num k) List<int>
Convert a CMYK color to RGB, where c, m, y, k values are in the range 0, 255. Returns a list r, g, b with values in the range 0, 255.
colorOffset(Image src, {int red = 0, int green = 0, int blue = 0, int alpha = 0}) Image
Add the red, green, blue and alpha values to the src image colors, a per-channel brightness.
contrast(Image? src, num contrast) Image?
Set the contrast level for the image src.
convolution(Image src, List<num> filter, {num div = 1.0, num offset = 0.0}) Image
Apply a 3x3 convolution filter to the src image. filter should be a list of 9 numbers.
copyCrop(Image src, int x, int y, int w, int h) Image
Returns a cropped copy of src.
copyCropCircle(Image src, {int? radius, Point? center}) Image
Returns a round cropped copy of src.
copyInto(Image dst, Image src, {int? dstX, int? dstY, int? srcX, int? srcY, int? srcW, int? srcH, bool blend = true, bool center = false}) Image
Copies a rectangular portion of one image to another image. dst is the destination image, src is the source image identifier.
copyRectify(Image src, {required Point topLeft, required Point topRight, required Point bottomLeft, required Point bottomRight, Image? toImage}) Image
Returns a copy of the src image, where the given rectangle has been mapped to the full image.
copyResize(Image src, {int? width, int? height, Interpolation interpolation = Interpolation.nearest}) Image
Returns a resized copy of the src image. If height isn't specified, then it will be determined by the aspect ratio of src and width. If width isn't specified, then it will be determined by the aspect ratio of src and height.
copyResizeCropSquare(Image src, int size) Image
Returns a resized and square cropped copy of the src image of size size.
copyRotate(Image src, num angle, {Interpolation interpolation = Interpolation.nearest}) Image
Returns a copy of the src image, rotated by angle degrees.
crand(Random rand) double
Return a random variable between -1,1.
decodeAnimation(List<int> data) Animation?
Decode the given image file bytes by first identifying the format of the file and using that decoder to decode the file into an Animation containing one or more Image frames.
decodeBmp(List<int> bytes) Image?
Decode a BMP formatted image.
decodeExr(List<int> bytes, {double exposure = 1.0}) Image?
Decode an OpenEXR formatted image, tone-mapped using the given exposure to a low-dynamic-range Image.
decodeGif(List<int> bytes) Image?
Decode a GIF formatted image (first frame for animations).
decodeGifAnimation(List<int> bytes) Animation?
Decode an animated GIF file. If the GIF isn't animated, the animation will contain a single frame with the GIF's image.
decodeIco(List<int> bytes) Image?
Decode an ICO image.
decodeImage(List<int> data) Image?
Decode the given image file bytes by first identifying the format of the file and using that decoder to decode the file into a single frame Image.
decodeJpg(List<int> bytes) Image?
Decode a JPG formatted image.
decodeNamedAnimation(List<int> bytes, String name) Animation?
Identify the format of the image using the file extension of the given name, and decode the given file bytes to an Animation with one or more Image frames. See also decodeAnimation.
decodeNamedImage(List<int> bytes, String name) Image?
Identify the format of the image using the file extension of the given name, and decode the given file bytes to a single frame Image. See also decodeImage.
decodePng(List<int> bytes) Image?
Decode a PNG formatted image.
decodePngAnimation(List<int> bytes) Animation?
Decode a PNG formatted animation.
decodePsd(List<int> bytes) Image?
Decode a Photoshop PSD formatted image.
decodeTga(List<int> bytes) Image?
Decode a Targa formatted image.
decodeTiff(List<int> bytes) Image?
Decode a TIFF formatted image.
decodeTiffAnimation(List<int> bytes) Animation?
Decode an multi-image (animated) TIFF file. If the tiff doesn't have multiple images, the animation will contain a single frame with the tiff's image.
decodeWebP(List<int> bytes) Image?
Decode a WebP formatted image (first frame for animations).
decodeWebPAnimation(List<int> bytes) Animation?
Decode an animated WebP file. If the webp isn't animated, the animation will contain a single frame with the webp's image.
ditherPixels(Image image, NeuralQuantizer quantizer, DitherKernel kernel, bool serpentine) Uint8List
drawChar(Image image, BitmapFont font, int x, int y, String char, {int? color}) Image
Draw a single character from char horizontally into image at position x,y with the given color.
drawCircle(Image image, int x0, int y0, int radius, int color) Image
Draw a circle into the image with a center of x0,y0 and the given radius and color.
drawImage(Image dst, Image src, {int? dstX, int? dstY, int? dstW, int? dstH, int? srcX, int? srcY, int? srcW, int? srcH, bool blend = true}) Image
Draw the image src onto the image dst.
drawLine(Image image, int x1, int y1, int x2, int y2, int color, {bool antialias = false, num thickness = 1}) Image
Draw a line into image.
drawPixel(Image image, int x, int y, int color, [int opacity = 0xff]) Image
Draw a single pixel into the image, applying alpha and opacity blending.
drawRect(Image dst, int x1, int y1, int x2, int y2, int color) Image
Draw a rectangle in the image dst with the color.
drawString(Image image, BitmapFont font, int x, int y, String string, {int color = 0xffffffff, bool rightJustify = false}) Image
Draw a string horizontally into image horizontally into image at position x,y with the given color.
drawStringCentered(Image image, BitmapFont font, String string, {int? x, int? y, int color = 0xffffffff}) Image
Draw a string horizontally into image at position x,y with the given color. If x is omitted text is automatically centered into image If y is omitted text is automatically centered into image. If both x and y are provided it has the same behaviour of drawString method.
drawStringWrap(Image image, BitmapFont font, int x, int y, String string, {int color = 0xffffffff}) Image
Same as drawString except the strings will wrap around to create multiple lines. You can load your own font, or use one of the existing ones such as: arial_14, arial_24, or arial_48.
dropShadow(Image src, int hShadow, int vShadow, int blur, {int shadowColor = 0xa0000000}) Image
Create a drop-shadow effect for the image.
emboss(Image src) Image
Apply an emboss convolution filter.
encodeBmp(Image image) List<int>
encodeCur(Image image) List<int>
Encode an image to the CUR format.
encodeCurImages(List<Image> images) List<int>
Encode a list of images to the CUR format.
encodeGif(Image image, {int samplingFactor = 10}) List<int>
Encode an image to the GIF format.
encodeGifAnimation(Animation anim, {int samplingFactor = 30}) List<int>?
Encode an animation to the GIF format.
encodeIco(Image image) List<int>
Encode an image to the ICO format.
encodeIcoImages(List<Image> images) List<int>
Encode a list of images to the ICO format.
encodeJpg(Image image, {int quality = 100}) List<int>
Encode an image to the JPEG format.
encodeNamedImage(Image image, String name) List<int>?
Identify the format of the image and encode it with the appropriate Encoder.
encodePng(Image image, {int level = 6}) List<int>
Encode an image to the PNG format.
encodePngAnimation(Animation anim, {int level = 6}) List<int>?
Encode an animation to the PNG format.
encodeTga(Image image) List<int>
Encode an image to the Targa format.
fill(Image image, int color) Image
Set all of the pixels of an image to the given color.
fillCircle(Image image, int x0, int y0, int radius, int color) Image
Draw and fill a circle into the image with a center of x0,y0 and the given radius and color.
fillFlood(Image src, int x, int y, int color, {num threshold = 0.0, bool compareAlpha = false}) Image
Fill the 4-connected shape containing x,y in the image src with the given color.
fillRect(Image src, int x1, int y1, int x2, int y2, int color) Image
Fill a rectangle in the image src with the given color with the corners x1,y1 and x2,y2.
findDecoderForData(List<int> data) Decoder?
Find a Decoder that is able to decode the given image data. Use this is you don't know the type of image it is. Since this will validate the image against all known decoders, it is potentially very slow.
findStringHeight(BitmapFont font, String string) int
findTrim(Image src, {TrimMode mode = TrimMode.transparent, Trim sides = Trim.all}) List<int>
Find the crop area to be used by the trim function. Returns the coordinates as x, y, width, height. You could pass these coordinates to the copyCrop function to crop the image.
flip(Image src, Flip mode) Image
Flips the src image using the given mode, which can be one of: Flip.horizontal, Flip.vertical, or Flip.both.
flipHorizontal(Image src) Image
Flip the src image horizontally.
flipVertical(Image src) Image
Flip the src image vertically.
gaussianBlur(Image src, int radius) Image
Apply gaussian blur to the src image. radius determines how many pixels away from the current pixel should contribute to the blur, where 0 is no blur and the larger the radius, the stronger the blur.
getAlpha(int color) int
Get the alpha channel from the color.
getBlue(int color) int
Get the blue channel from the color.
getChannel(int color, Channel channel) int
Get the channel from the color.
getColor(int r, int g, int b, [int a = 255]) int
Get the color with the given r, g, b, and a components.
getDecoderForNamedImage(String name) Decoder?
Return the Decoder that can decode image with the given name, by looking at the file extension. See also findDecoderForData to determine the decoder to use given the bytes of the file.
getGreen(int color) int
Get the green channel from the color.
getLuminance(int color) int
Returns the luminance (grayscale) value of the color.
getLuminanceRgb(int r, int g, int b) int
Returns the luminance (grayscale) value of the color.
getRed(int color) int
Get the red channel from the color.
grand(Random rand) double
Return a random variable following a gaussian distribution and a standard deviation of 1.
grayscale(Image src) Image
Convert the image to grayscale.
hdrBloom(HdrImage hdr, {double radius = 0.01, double weight = 0.1}) HdrImage
Applies an HDR bloom filter to the image, in-place.
hdrGamma(HdrImage hdr, {double gamma = 2.2}) HdrImage
Apply gamma scaling to the HDR image, in-place.
hdrToImage(HdrImage hdr, {num? exposure}) Image
Convert a high dynamic range image to a low dynamic range image, with optional exposure control.
hslToRgb(num hue, num saturation, num lightness) List<int>
Convert an HSL color to RGB, where h is specified in normalized degrees 0, 1 (where 1 is 360-degrees); s and l are in the range 0, 1. Returns a list r, g, b with values in the range 0, 255.
hsvToRgb(num hue, num saturation, num brightness) List<int>
Convert an HSV color to RGB, where h is specified in normalized degrees 0, 1 (where 1 is 360-degrees); s and l are in the range 0, 1. Returns a list r, g, b with values in the range 0, 255.
invert(Image src) Image
Invert the colors of the src image.
isBlack(int color) bool
check if color is white
isWhite(int color) bool
check if color is white
labToRgb(num l, num a, num b) List<int>
Convert a CIE-L*ab color to RGB.
labToXyz(num l, num a, num b) List<int>
Convert a CIE-L*ab color to XYZ.
maskFlood(Image src, int x, int y, {num threshold = 0.0, bool compareAlpha = false, int fillValue = 255}) Uint8List
Create a mask describing the 4-connected shape containing x,y in the image src.
minMax(Image image) List<int>
Find the minimum and maximum color value in the image. Returns a list as <min, max>.
noise(Image image, num sigma, {NoiseType type = NoiseType.gaussian, Random? random}) Image
Add random noise to pixel values. sigma determines how strong the effect should be. type should be one of the following: NoiseType.gaussian, NoiseType.uniform, NoiseType.salt_pepper, NoiseType.poisson, or NoiseType.rice.
normalize(Image src, int minValue, int maxValue) Image
Linearly normalize the colors of the image. All color values will be mapped to the range minValue, maxValue inclusive.
pixelate(Image src, int blockSize, {PixelateMode mode = PixelateMode.upperLeft}) Image
Pixelate the src image.
prand(Random rand, double z) int
Return a random variable following a Poisson distribution of parameter z.
quantize(Image src, {int numberOfColors = 256, QuantizeMethod method = QuantizeMethod.neuralNet}) Image
Quantize the number of colors in image to 256.
readFont(String font, Image map) BitmapFont
Decode a BitmapFont from the contents of font definition (.fnt) file, and an Image that stores the font map.
readFontZip(List<int> bytes) BitmapFont
Decode a BitmapFont from the contents of a zip file that stores the .fnt font definition and associated PNG images.
readJpg(List<int> bytes) Image?
Renamed to decodeJpg, left for backward compatibility.
readPng(List<int> bytes) Image?
Renamed to decodePng, left for backward compatibility.
readTga(List<int> bytes) Image?
Renamed to decodeTga, left for backward compatibility.
reinhardToneMap(HdrImage hdr) HdrImage
Applies Reinhard tone mapping to the hdr image, in-place.
remapColors(Image src, {Channel red = Channel.red, Channel green = Channel.green, Channel blue = Channel.blue, Channel alpha = Channel.alpha}) Image
Remap the color channels of the image. red, green, blue and alpha should be set to one of the following: Channel.red, Channel.green, Channel.blue, Channel.alpha, or Channel.luminance. For example, remapColors(src, red: Channel.green, green: Channel.red); will swap the red and green channels of the image. remapColors(src, alpha: Channel.luminance) will set the alpha channel to the luminance (grayscale) of the image.
rgbToHsl(num r, num g, num b) List<num>
Convert an RGB color to HSL, where r, g and b are in the range 0, 255. Returns a list h, s, l with values in the range 0, 1.
rgbToLab(num r, num g, num b) List<num>
Convert a RGB color to CIE-L*ab.
rgbToXyz(num r, num g, num b) List<num>
Convert a RGB color to XYZ.
scaleRgba(Image src, int r, int g, int b, int a) Image
separableConvolution(Image src, SeparableKernel kernel) Image
Apply a generic separable convolution filter the src image, using the given kernel.
sepia(Image src, {num amount = 1.0}) Image
Apply sepia tone to the image.
setAlpha(int color, int value) int
Returns a new color where the alpha channel of color has been replaced by value.
setBlue(int color, int value) int
Returns a new color where the blue channel of color has been replaced by value.
setChannel(int color, Channel channel, int value) int
Returns a new color, where the given color's channel has been replaced with the given value.
setGreen(int color, int value) int
Returns a new color where the green channel of color has been replaced by value.
setRed(int color, int value) int
Returns a new color where the red channel of color has been replaced by value.
smooth(Image src, num w) Image
Apply a smoothing convolution filter to the src image.
sobel(Image src, {num amount = 1.0}) Image
Apply Sobel edge detection filtering to the src Image.
trim(Image src, {TrimMode mode = TrimMode.transparent, Trim sides = Trim.all}) Image
Automatically crops the image by finding the corners of the image that meet the mode criteria (not transparent or a different color).
vignette(Image src, {num start = 0.3, num end = 0.75, num amount = 0.8}) Image
writeJpg(Image image, {int quality = 100}) List<int>
Renamed to encodeJpg, left for backward compatibility.
writePng(Image image, {int level = 6}) List<int>
Renamed to encodePng, left for backward compatibility.
writeTga(Image image) List<int>
Renamed to encodeTga, left for backward compatibility.
xyzToLab(num x, num y, num z) List<num>
Convert a XYZ color to CIE-L*ab.
xyzToRgb(num x, num y, num z) List<int>
Convert an XYZ color to RGB.

Exceptions / Errors

ImageException
An exception thrown when there was a problem in the image library.