Skip to content
@deckyard/magick

magick cheatsheet

Every export of @deckyard/magick. Guides are listed in the introduction.

jennifer
import "@deckyard/magick/" as magick;

Every failure is Error{kind: "magick"}. A c argument is a Config, an img an Image.

Constants

ConstantValueMeaning
ERROR_KIND"magick"the kind of every error the deck throws

Types

Config

FieldMeaning
binary as stringthe ImageMagick 7 program
formats as list of stringthe coders files may be read and written with
memory as stringpixel memory limit, e.g. 256MiB
disk as stringpixel-cache disk limit, e.g. 1GiB
area as stringthe largest image in pixels, e.g. 128MP
side as stringthe widest or tallest image, e.g. 16KP
timeoutMs as inthow long one command may run

Image

FieldMeaning
input as stringthe pinned input, PNG:photo.png or PNG:-
data as bytesthe image bytes, when opened from bytes
fromBytes as boolwhether data is the input
ops as list of stringthe operations' arguments

Info

FieldMeaning
format as stringthe coder, e.g. PNG
width as intwidth in pixels
height as intheight in pixels
colorspace as stringe.g. sRGB, Gray, CMYK
depth as intbits per channel
frames as intframes or pages
orientation as stringEXIF orientation; Undefined for none
opaque as boolno pixel is transparent

Comparison

FieldMeaning
value as floatthe metric in ImageMagick's units
normalized as floatthe metric on a 0 to 1 scale

Configuration

FunctionReturnsDoes
magick.config()Configsafe defaults
magick.defaultFormats()list of stringthe raster formats allowed by default
magick.withBinary(c, binary)Configanother magick program
magick.withFormats(c, formats)Configreplace the allowed formats
magick.allowFormat(c, format)Configallow one more, e.g. SVG for trusted files
magick.withLimits(c, memory, disk, area, side)Configresource limits
magick.withTimeout(c, ms)Configper-command timeout, at least 1000
magick.version(c)stringthe ImageMagick version line
magick.available(c)boolwhether ImageMagick 7 runs

Opening and writing

FunctionReturnsDoes
magick.open(c, path)Imagea file, format from the extension
magick.openAs(c, path, format)Imagea file in a named format
magick.fromBytes(c, data, format)Imagebytes in a named format
magick.write(c, img, path)nullrun the operations, write; format from the extension
magick.writeAs(c, img, path, format)nullthe same, in a named format
magick.encode(c, img, format)bytesrun the operations, return the bytes

Operations

FunctionReturnsDoes
magick.resize(img, width, height)Imagefit in a box; 0 for any
magick.shrinkOnly(img, width, height)Imagefit, never enlarge
magick.resizeExact(img, width, height)Imageexactly this size
magick.thumbnail(img, width, height)Imagefit and drop metadata
magick.cover(img, width, height)Imagefill the box, cut the overflow
magick.crop(img, x, y, width, height)Imagecut out a rectangle
magick.pad(img, width, height, fill)Imagecentre on a canvas
magick.rotate(img, degrees)Imagerotate clockwise
magick.firstFrame(img)Imageread only the first frame
magick.autoOrient(img)Imageupright by EXIF orientation
magick.flip(img)Imagemirror top to bottom
magick.flop(img)Imagemirror left to right
magick.grayscale(img)Imageshades of grey
magick.strip(img)Imageremove metadata
magick.quality(img, quality)Imagelossy quality, 1 to 100
magick.blur(img, sigma)ImageGaussian blur
magick.sharpen(img, sigma)Imagesharpen
magick.border(img, pixels, fill)Imagea border
magick.annotate(img, text, where, x, y, size, fill)Imageliteral text
magick.overlay(img, over, where, x, y)Imageanother image on top

Inspecting

FunctionReturnsDoes
magick.identify(c, path)Infofacts about a file
magick.identifyBytes(c, data, format)Infofacts about bytes
magick.compare(c, a, b, metric)Comparisondifference of two images
magick.montage(c, inputs, path, columns, tileWidth, tileHeight)nulla contact sheet
magick.run(c, args)stringmagick with your own, unchecked arguments