Methods
Every image method and helper in the jimp package, grouped by what it does.
Image methods change the image in place and return it, so calls can be chained:
image.resize({ w: 300 }).blur(2).greyscale();Every thumbnail below was made by Jimp in your browser from the same photo. Select a method for its options, an example and a live playground. For the full generated types of every export, see the type reference.
Loading and saving
Create images from files, URLs, buffers or raw pixels, then encode them again.
These are part of @jimp/core, so every Jimp has them.
Load an image from a file path, a URL, a Buffer, a typed array or a Blob.
Jimp.fromBuffer()Decode an image that's already in memory, such as a Buffer or a Blob.
Jimp.fromBitmap()Create an image from raw RGBA pixel data, such as canvas ImageData.
new Jimp()Create a blank image of a given size and background color.
Rendering…getBuffer()Encode the image in a format and get the bytes as a Buffer.
getBase64()Encode the image in a format and get it as a base64 data URL.
Rendering…blurhash()Encode the image as a short BlurHash string for blurred placeholders.
decodeBlurhash()Turn a BlurHash string back into a blurred placeholder image.
write()Encode the image and save it to a file. The extension picks the format.
Jimp.readFrames()Load every frame of an animated GIF or PNG, or every page of a multi-page TIFF.
Jimp.encodeFrames()Encode several images as an animated GIF or a multi-page TIFF.
Jimp.writeFrames()Save several images to a file as an animated GIF or a multi-page TIFF.
clone()Copy the image so you can change the copy and keep the original.
apply()Run a list of edits stored as data, such as JSON from a request or a saved preset.
Size and shape
Change the size of the canvas, cut it down, rotate, skew or bend it.
Resize to a width and/or height. Pass one side to keep the aspect ratio.
Rendering…scale()Scale the width and height by the same factor.
Rendering…scaleToFit()Scale the image to fit inside a box, keeping the aspect ratio.
Rendering…cover()Scale and crop the image to fill a box exactly.
coverRect()Measure the part of the image cover would keep, without cropping.
Rendering…contain()Scale the image to fit inside a box and pad the rest.
Rendering…crop()Cut out a rectangle of the image.
Rendering…autocrop()Remove borders of the same color from the edges.
autocropRect()Measure the rectangle autocrop would keep, without cropping.
Rendering…rotate()Rotate the image counter-clockwise by any angle.
Rendering…skew()Slant the image along x and/or y by an angle, like CSS skew().
Rendering…affine()Transform the image with a 2D matrix: scale, skew, flip, rotate, move.
Rendering…flip()Mirror the image horizontally, vertically or both.
Rendering…circle()Make everything outside a circle transparent.
roundCorners()Round the corners of the image, like CSS border-radius.
Rendering…border()Add a solid border around the image, optionally with rounded corners.
Rendering…fisheye()Bulge the center of the image like a fisheye lens.
Rendering…displace()Move pixels right and down using a displacement map image.
Blur and effects
Soften, sharpen, denoise, pixelate or filter the image, grow and shrink shapes with erode and dilate, or add a shadow.
Apply a fast blur with a radius in pixels.
Rendering…gaussian()Apply a true Gaussian blur. Smoother than blur, but slower.
Rendering…sharpen()Sharpen edges with an unsharp mask, with strength, radius and threshold.
median()Remove specks and salt-and-pepper noise with a median filter.
bilateral()Smooth grain and JPEG noise in photos while keeping edges sharp.
Rendering…pixelate()Pixelate the whole image or a region of it.
Rendering…dither()Dither to black and white or a few levels, or add a subtle RGB565 pattern.
Rendering…grain()Add film grain that's the same every time, or just enough noise to hide gradient banding.
Rendering…erode()Grow dark areas by taking the darkest pixel in each neighborhood.
Rendering…dilate()Grow bright areas by taking the brightest pixel in each neighborhood.
Rendering…open()Remove small bright specks while keeping larger shapes the same size.
Rendering…close()Fill small dark holes and gaps while keeping larger shapes the same size.
Rendering…convolute()Apply a convolution kernel to the image or a region.
Rendering…convolution()Apply a convolution kernel with a choice of edge handling.
Rendering…boxShadow()Add a CSS-style drop shadow, growing the image to fit it.
shadow()Add a shadow shaped like the image. Not included in the jimp package.
Color
Adjust exposure, brightness, contrast and color, convert between color spaces, or reduce the palette.
Apply color actions such as hue, saturate, tint, mix and multiply.
toColorSpace()Convert the pixels to sRGB or Display P3 and update the color profile.
Rendering…brightness()Multiply every color channel. 1 leaves the image unchanged.
Rendering…contrast()Raise or lower the contrast, from -1 to +1.
Rendering…exposure()Brighten or darken by stops, like a camera's exposure setting.
Rendering…vibrance()Boost muted colors more than vivid ones, from -1 to +1.
Rendering…greyscale()Remove all color from the image.
Rendering…invert()Invert the red, green and blue channels.
Rendering…sepia()Apply a warm sepia tone.
Rendering…gradientMap()Recolor an image along a gradient, like a duotone.
Rendering…posterize()Reduce each color channel to a number of levels.
Rendering…normalize()Stretch each channel to use the full 0 to 255 range.
Rendering…colorGrade()Color grade with a 3D LUT from a .cube file or a Hald image.
parseCubeLut()Read a .cube file into a 3D LUT for lut().
Rendering…threshold()Turn pixels at or above a cut-off into one gray value.
Rendering…otsuThreshold()Find the best threshold cut-off for an image with Otsu's method.
Rendering…quantize()Reduce the image to a limited palette of colors.
palette()Extract an image's main colors, most common first, with how much each covers.
dominantColor()Find the color that covers most of an image, for backgrounds and accents.
Rendering…opacity()Multiply the alpha channel by a factor from 0 to 1.
Rendering…fade()Make the image more transparent by a factor from 0 to 1.
Rendering…opaque()Make every pixel fully opaque.
Compositing
Draw one image on top of another.
Drawing
Draw antialiased lines, rectangles, ellipses, polygons and SVG paths in colors or gradients, or flood fill an area. See Drawing for paints, strokes and fill rules.
Draw a straight, antialiased line in a color or gradient.
Rendering…drawRect()Draw a filled or outlined rectangle, optionally with rounded corners.
Rendering…drawEllipse()Draw a filled or outlined ellipse or circle around a center point.
Rendering…drawPolygon()Draw a polygon or polyline through a list of points.
Rendering…drawPath()Draw SVG path data: lines, curves and arcs, filled or stroked.
Rendering…floodFill()Fill the area connected to a point, like a paint bucket.
render()Lay out boxes, text and images like flexbox and draw them.
Text
Draw and measure text with bitmap fonts or TrueType, OpenType and WOFF fonts.
Draw text on the image with a bitmap or TrueType font.
loadFont()Load a bitmap font (.fnt) to use with print.
loadTTF()Load a TrueType, OpenType or WOFF font to print at any size.
measureText()Measure the width of a string in a font.
measureTextHeight()Measure the height of wrapped text in a font.
Pixels
Read and write individual pixels, or loop over all of them.
Read the color of one pixel as an RGBA integer.
Rendering…setPixelColor()Set the color of one pixel from an RGBA integer.
Rendering…getPixelIndex()Get the position of a pixel in the bitmap's data buffer.
hasAlpha()Check whether any pixel is not fully opaque.
Rendering…scan()Run a function for every pixel in the image or a region.
Rendering…scanIterator()Loop over the pixels of the image or a region with for...of.
Comparing images
Tell whether two images look alike, with perceptual hashes or a pixel diff.
Compute a perceptual hash of the image as a string in any base.
pHash()Compute the perceptual hash of the image as a binary string.
distanceFromHash()Compare the image to a perceptual hash.
distance()Compare two images by their perceptual hashes.
compareHashes()Compare two perceptual hashes from pHash() or hash().
Rendering…diff()Compare two images pixel by pixel and get a diff image.
Utilities
Functions for converting and comparing colors.
Convert an RGBA integer such as 0xff0000ff to { r, g, b, a }.
rgbaToInt()Convert red, green, blue and alpha values to an RGBA integer.
cssColorToHex()Convert a CSS color string to an RGBA integer.
Rendering…colorDiff()Measure how different two colors are, from 0 to 1.
Rendering…limit255()Clamp a number to the 0 to 255 range.