jimp

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package jimp provides the image primitives the multimedia operations are built on, matching the Jimp library CyberChef uses.

Jimp decodes to a straight (non-premultiplied) RGBA bitmap, applies a pixel transform, then re-encodes to the source format, with GIF re-encoded as PNG. This package works on an image.NRGBA, which is also straight RGBA, so the pixel results agree exactly and lossless formats (PNG, BMP, TIFF) come out identical. JPEG is re-encoded lossily and so is an approximation.

Index

Constants

This section is empty.

Variables

View Source
var (
	HAlignIndex = map[string]int{"Left": 0, "Center": 1, "Right": 2}
	VAlignIndex = map[string]int{"Top": 0, "Middle": 1, "Bottom": 2}
)

HAlignIndex/VAlignIndex map alignment labels to Jimp's 0/1/2 factors.

View Source
var BlurMaxRadius = len(blurMulTable)

BlurMaxRadius bounds BlurFast's radius: the fixed-point tables have one entry per radius, so a radius at or past their length has no entry.

View Source
var StrategyNames = map[string]string{
	"Nearest Neighbour": "nearestNeighbor",
	"Bilinear":          "bilinearInterpolation",
	"Bicubic":           "bicubicInterpolation",
	"Hermite":           "hermiteInterpolation",
	"Bezier":            "bezierInterpolation",
}

StrategyNames maps cchef's option labels to Jimp's ResizeStrategy keys.

Functions

func Blit

func Blit(dst, src *image.NRGBA, x, y int)

Blit composites src onto dst at (x,y) using Jimp's over operator.

func BlitRect

func BlitRect(dst, src *image.NRGBA, x, y, srcX, srcY, srcW, srcH int)

BlitRect composites the srcW×srcH region of src at (srcX,srcY) onto dst at (x,y). Source pixels outside src read as 0, as they do in Jimp.

func BlurFast

func BlurFast(img *image.NRGBA, r int)

BlurFast applies Mario Klingemann's Superfast Blur (two passes) with the mulTable/shgTable fixed-point tables. r must be in [1, 256].

func Clone

func Clone(img *image.NRGBA) *image.NRGBA

Clone returns a deep copy of a dense NRGBA image.

func Contain

func Contain(img *image.NRGBA, w, h, alignH, alignV int, mode string) *image.NRGBA

Contain scales img to fit within w×h and centres it (per alignment) on a transparent canvas.

func Cover

func Cover(img *image.NRGBA, w, h, alignH, alignV int, mode string) (*image.NRGBA, error)

Cover scales img to fill w×h and crops the aligned region.

func CropExact

func CropExact(img *image.NRGBA, x, y, w, h int) (*image.NRGBA, error)

CropExact extracts the w×h region at (x,y). Returns an error if the region falls outside the source (Jimp throws a RangeError, which CyberChef surfaces).

func Decode

func Decode(data []byte, invalidMsg string) (*image.NRGBA, string, error)

Decode validates that data is an image, decodes it to a dense straight-RGBA bitmap, and returns the bitmap plus the source format name.

func Gaussian

func Gaussian(img *image.NRGBA, r float64)

Gaussian applies a Gaussian blur. It reproduces Jimp's in-place scan, where the destination pixel is written inside the kernel's row loop, so later pixels convolve over already-blurred neighbours.

func Limit255

func Limit255(n int) int

Limit255 clamps to the 0–255 range (Jimp's Limit255).

func Resize

func Resize(img *image.NRGBA, wf, hf float64, mode string) *image.NRGBA

Resize resizes img to wf×hf (rounded, min 1) using the named strategy.

func Scale

func Scale(img *image.NRGBA, f float64, mode string) *image.NRGBA

Scale scales img by factor f.

func ScaleToFit

func ScaleToFit(img *image.NRGBA, wf, hf float64, mode string) *image.NRGBA

ScaleToFit scales img to fit within wf×hf, preserving aspect ratio.

func ToNRGBA

func ToNRGBA(img image.Image) *image.NRGBA

ToNRGBA returns img as a dense image.NRGBA anchored at the origin.

func Transform

func Transform(data []byte, invalidMsg string, transform func(*image.NRGBA) *image.NRGBA) ([]byte, error)

Transform runs the common decode -> transform -> encode pipeline shared by the Multimedia image operations. transform receives the decoded bitmap and returns the (possibly new) bitmap to encode.

func TransformE

func TransformE(data []byte, invalidMsg string, transform func(*image.NRGBA) (*image.NRGBA, error)) ([]byte, error)

TransformE is like imageTransform but the transform may fail (e.g. an out-of-bounds crop).

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL