Repository navigation
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 anAnimationfor files with several frames,Image.decode()the first frame.Animationholds itsframesinstead of extendingArray,Frameholds animageinstead of extendingImage, theGIFclass is gone, and loop counts areInfinity(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
TypeErrororRangeErrorthat says what was passed, instead of being clamped or ignored. - Removed:
Image.encode(),contain()/cover()(nowresize({ fit })), the color helpers onImage(nowColors),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()andoutline(). Image.encodeGIF()for single images, dithering options for GIF encoding, andsubsamplingfor JPEG.- Limits for untrusted input:
renderSVG()andrenderText()bound their memory and work and throw a catchableLimitError(new:maxLayerPixels,maxPixelsfor 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.