Skip to content

4.0.0

Latest

Choose a tag to compare

@matmen matmen released this 23 Nov 16:19
Immutable release. Only release title and notes can be modified.

ImageScript 4.0 is out. It's the first major release since 3.0: everything 3.x marked as deprecated is gone, the API is consistent throughout, and the library got a lot harder to break with large or hostile input.

Upgrading from 3.x

Update to 3.20.5 first and fix its deprecation warnings: your editor and tsc show them, and each one names its replacement. Then switch to 4.0 and go through the migration guide, which lists every change and has a checklist of things to search your code for.

Breaking changes

  • Options objects everywhere: every method takes one options object instead of positional arguments (encodeJPEG({ quality: 80 }), composite(image, { x, y }), resize({ width, mode: 'bicubic' })), and modes are plain strings instead of constants.
  • Animations: decode() returns an Animation for files with several frames, Image.decode() the first frame. Animation holds its frames instead of extending Array, Frame holds an image instead of extending Image, the GIF class is gone, and loop counts are Infinity (forever) or a count.
  • Behavior that changed: rotate() turns clockwise like CSS, quantize() dithers by default, encodeJPEG() puts transparent pixels on a background, WebP at quality 100 is lossless, and encoded files carry no creation time unless you pass one.
  • Stricter checks: wrong types, out-of-range values and invalid modes throw a TypeError or RangeError that says what was passed, instead of being clamped or ignored.
  • Removed: Image.encode(), contain()/cover() (now resize({ fit })), the color helpers on Image (now Colors), drawBox()/drawCircle(), getRGBAAt() and the deprecated types.

New

  • resize({ width, height, fit }) with 'inside', 'contain' and 'cover', on images, frames and animations.
  • More for animations and frames: clone(), crop(), flip(), scale(), trim(), rotate(), transform(), dropShadow() and outline().
  • Image.encodeGIF() for single images, dithering options for GIF encoding, and subsampling for JPEG.
  • Limits for untrusted input: renderSVG() and renderText() bound their memory and work and throw a catchable LimitError (new: maxLayerPixels, maxPixels for text).

Fixes

  • Cut-off JPEG and lossy WebP files throw like the other formats, and damaged files that could run the process out of memory or time are refused early.
  • Many fixes in SVG rendering, text layout, the encoders and animation compositing: the changelog lists them all.

Also new

  • The docs have guides: Choosing ImageScript, Coming from Jimp, shrinking images before upload, social cards and favicons.
  • The playground runs 4.0, loads faster and has new examples.