Skip to content

Image version 0.73.0

Latest

Choose a tag to compare

@kipcole9 kipcole9 released this 30 Oct 01:25
· 81 commits to main since this release

Image 0.73.0

This is the changelog for Image version 0.73.0 released on October 28th, 2026. For older changelogs please consult the release tag on GitHub

A large release on the way to 1.0, with 30 breaking changes in five areas:

  • One opacity vocabulary — opacity is now the value a caller sets and alpha the band it is written to, so transparency is gone and Image.opacity/2 is deprecated in favour of Image.multiply_alpha/2.

  • Alpha and colour scale to the interpretation — 16-bit and scRGB images were given 8-bit values, leaving them 0.4% opaque or out of range, which corrects Image.add_alpha/2, Image.Pixel.to_pixel/3, Image.fade/2 and Image.drop_shadow/2.

  • Errors instead of exceptions — around twenty functions return {:error, %Image.Error{}} where they raised FunctionClauseError, ArithmeticError or a NimbleOptions error, and Image.Pixel returns an Image.Error on every path.

  • Image.compare/3 works beyond three-band sRGB — it failed outright on a greyscale image, and its default :ae metric counted only the first band, so images differing in any other compared as identical.

  • Image.reduce_colors/2 keeps its input's type — it returns {:u, 8} rather than {:f, 32}, and the colorspace it was given rather than always sRGB.

It also adds Image.copy_memory/1, for the pipelines that need to be consumed more than once.

Many many thanks to @hlindset who took on the monumental task of significantly improving the way in which standard vocabulary is used, validated and applied. Thank you very much Håvard.

Added

  • Adds :background and :interpolate options to the mapim-based transformations — Image.ripple/2, Image.to_polar_coordinates/2 and Image.distort/4 gain both, Image.to_rectangular_coordinates/2, Image.warp_perspective/4, Image.straighten_perspective/3 and Image.map/3 gain :interpolate, and Image.distort/4 also gains :extend_mode (:background or :copy). :interpolate defaults to :bilinear except for Image.distort/4, which keeps its :bicubic default. (#216)

  • Adds Image.chroma_color!/1 as a companion to Image.chroma_color/1. (#219)

  • Adds Image.Pixel.strip_alpha/2 which returns a resolved pixel without its alpha component. It consolidates the truncation that Image.flatten/2, Image.chroma_mask/2, Image.Options.Trim and Image.Options.Write each did separately before. (#222)

  • Adds Image.Pixel.put_alpha/3 and Image.Pixel.put_alpha!/3, which return a pixel with its alpha component set to a given opacity, scaled to the image's alpha band. The pixel is returned unchanged when the image has no alpha band. (#231)

  • Adds Image.Pixel.opacity_fraction/1 and Image.Pixel.opacity_fraction!/1, which return an opacity as a fraction of full opacity. Unlike Image.Pixel.alpha_for/2 the result belongs to no particular image. (#231)

  • Adds Image.Pixel.alpha_for/2 and Image.Pixel.alpha_for!/2, which scale an opacity to the alpha band of a given image, whose range depends on the interpretation. (#231)

  • Adds Image.multiply_alpha/2 and Image.multiply_alpha!/2, which multiply an image's alpha band by a 0.0..1.0 factor. They replace Image.opacity/2, which is deprecated and delegates to them.

  • Adds Image.copy_memory/1 and Image.copy_memory!/1, which return an image guaranteed to be resident in memory. A thumbnail taken from a pathname streams from the file and can only be consumed once, so a pipeline that runs over one more than once needs this. (#175)

  • Documents the pipeline depth limit in the Performance guide. A loop that accumulates more than roughly 150 pending operations exhausts the stack of the thread libvips is evaluated on and takes the VM down; flattening every 25 to 50 operations with Image.copy_memory/1 avoids it. (#192)

  • Adds text_fill_color: :markup to Image.Text.text/2 and Image.Text.simple_text/2, which takes the color of each part of the text from the Pango markup so one string can render in more than one color. Text with no color set in the markup renders black. (#233)

Changed

  • Image.Pixel.to_pixel/3 now applies the :opacity option to a color given as a list of numbers. It was previously ignored for those, so to_pixel(image, [255, 0, 0, 255], opacity: 0.5) returned a fully opaque pixel. (#231)

  • The :opacity options of Image.Shape and the :background_fill_opacity / :background_stroke_opacity options of Image.Text.text/2 accept any t:Image.Pixel.opacity/0 rather than only a float, so every function taking an opacity now accepts the same values. (#231)

  • Breaking: The :opacity option of Image.drop_shadow/2 accepts any t:Image.Pixel.opacity/0 rather than any number in 0.0..1.0. Only 1 changes meaning — it was fully opaque and is now 8-bit notation for 1/255, so use 1.0 instead; 0 remains fully transparent. (#231)

  • Breaking: Image.Pixel returns an Image.Error on every error path, which reaches every function that resolves a color, including the :background options. An unsupported interpretation was a bare string and is now reason: :unsupported_interpretation; an invalid color was the Color library's own exception and is now reason: :invalid_color with the color in value. (#231)

  • Breaking: An invalid opacity reports reason: :invalid_opacity instead of :invalid_transparency. (#231)

  • Breaking: Image.Pixel.to_pixel/3 returns linear light values for an :scrgb image, which affects every function that resolves a color against one. It previously returned gamma encoded sRGB, so a color drawn onto an scRGB image came out too bright and desaturated. (#230)

  • Breaking: Image.Pixel.to_pixel/3 returns relative luminance (CIE Y) for a single band :scrgb image. It previously returned a 0..255 integer, so :white resolved to 255 rather than 1.0. (#230)

  • Breaking: Image.Pixel.to_pixel/3 no longer rounds a float :opacity to a byte before scaling it, so opacity: 0.5 resolves to 0.5 on an :scrgb image and 32768 on a 16-bit image where both previously went via 128 and came out as 0.50196 and 32896. Interpretations with an 8-bit alpha band are unaffected, including Lab and LCH. (#231)

  • Image.add_alpha/2 accepts a float in 0.0..1.0 as well as the integer and atom forms it already took. An integer is a fraction of 255, so a float is the only way to add exactly half opacity to a 16-bit or :scrgb image. (#231)

  • Image.add_alpha/2 returns {:error, %Image.Error{reason: :invalid_opacity}} for an invalid opacity, where it previously raised FunctionClauseError. (#231)

  • Breaking: Image.add_alpha/2 scales the alpha band it adds to the image's interpretation, so :opaque resolves to 65535 on a 16-bit image and 1.0 on an :scrgb image where it previously wrote 255 into both, leaving 16-bit images 0.4% opaque and scRGB images out of range. An integer is now a fraction of 255, so 128 means the same opacity everywhere; interpretations with an 8-bit alpha band are unaffected, including Lab and LCH. (#231)

  • Breaking: Image.average/1 and Image.chroma_color/1 now return {:ok, [number()]} | {:error, Image.Error.t()} instead of a bare list on success. The previous success type was documented as Pixel.t() but was always a list of numbers. (#219)

  • Breaking: Image.warp_perspective/4 and Image.straighten_perspective/3 now preserve image alpha instead of always flattening, so the band count and pixels of the result may change; images without alpha are unaffected. An omitted :background defers to libvips' fill rather than defaulting to :black, matching the other background-taking functions. (#216)

  • Breaking: Image.map/3 now fills exposed pixels of an alpha image with transparent black rather than opaque black, matching the :background default of the other mapim transformations. (#216)

  • Breaking: Image.to_rectangular_coordinates/2 now clamps boundary samples to the source edge color instead of blending towards a zero fill. (#216)

  • Breaking: The Image.Options.* validators accept keyword lists only, so passing a pre-validated map now raises FunctionClauseError and map() is removed from 22 option union types. This affects Image.blur/2, Image.feather/2, Image.sharpen/2, Image.modulate/2, Image.vignette/2, Image.embed/4, Image.chroma_mask/2, Image.chroma_key/2, Image.trim/2, Image.find_trim/2, Image.vibrance/3, Image.rotate/3, Image.affine/3, Image.shear/4, Image.resize/3, Image.thumbnail/3, the Image.Draw functions and all their ! variants; hoist the color resolution instead if the validation cost matters in a tight loop. (#220)

  • Breaking: Image.from_binary/2 returns {:error, %Image.Error{}} rather than {:error, binary}, and Image.write/3 to a Plug.Conn returns %Image.Error{reason: :closed} rather than {:error, :closed}. Every error path in Image.open/2 and Image.write/3 now returns a structured Image.Error with :operation set. (#218)

  • Breaking: Image.Error.exception(reason: :enoent, path: path) now produces Image.Error.wrap/2's message, and a {atom, value} reason built through Image.Error.wrap/2 gains the "Image error: " prefix. (#218)

  • Breaking: Image.drop_shadow/2 returns {:error, %Image.Error{}} for a non-numeric :sigma instead of raising ArithmeticError, and its :opacity and :sigma errors now carry reason: :invalid_option with value set to {:opacity, value} or {:sigma, value}. :dx, :dy and unknown options remain unvalidated, pending a move to an Image.Options.DropShadow module. (#221)

  • Breaking: Image.chroma_mask/2, Image.chroma_key/2, Image.replace_color/2 and their ! variants now return {:error, %Image.Error{reason: :invalid_option}} when options from both masking strategies are supplied, or when only one of :greater_than and :less_than is supplied. The two strategies were always documented as mutually exclusive, but nothing enforced it: the color range strategy won and :color and :threshold were silently discarded, and a lone bound was discarded and replaced by auto chroma detection with the default threshold. (#224)

  • Breaking: Image.Scholar.k_means/2 returns {:ok, model} instead of a bare fitted Scholar.Cluster.KMeans on success, matching Image.Scholar.unique_colors/1 and the rest of the library. (#227)

  • Breaking: Image.k_means/2 and Image.reduce_colors/2 return {:error, %Image.Error{reason: :invalid_option}} for an invalid or unknown option instead of raising NimbleOptions.ValidationError, and the ! variants raise Image.Error rather than the NimbleOptions exception. operation is set to k_means or reduce_colors, and value is {key, value} for an invalid value or the list of keys for unknown options. (#227)

  • Breaking: Image.reduce_colors/2 returns {:u, 8} instead of {:f, 32}, rounding the result into the band format it clustered where k-means produced a float image that nothing cast back. libvips truncated those float values when casting on save, so output values can change by up to 1 per channel. (#229)

  • Breaking: Image.reduce_colors/2 returns the image in the colorspace it was given. A :cmyk image returns four bands and a greyscale image returns one, where previously every image came back as 3-band :srgb. (#229)

  • Image.reduce_colors/2 clamps :colors to the number of unique colors in the image. Previously a :colors greater than the image's pixel count failed. (#229)

  • Image.affine/3 and Image.rotate/3 now premultiply alpha explicitly only when the background is non-opaque, since libvips handles the other cases itself. Image.shear/4 and Image.translate/4 inherit this. (#217)

  • Image.multiply_alpha/2 returns {:error, %Image.Error{reason: :invalid_factor}} for a factor outside 0.0..1.0 or of the wrong type, where Image.opacity/2 previously raised FunctionClauseError. The ! variant raises Image.Error.

  • Deprecates Image.opacity/2 and Image.opacity!/2 in favour of Image.multiply_alpha/2 and Image.multiply_alpha!/2, whose argument is a multiplier rather than a t:Image.Pixel.opacity/0. The old names still work and delegate.

  • Image.brightness/2, Image.saturation/2, Image.vibrance/3, Image.dilate/2, Image.erode/2, Image.dhash/2, Image.pixelate/2, Image.rotate/3, Image.shear/4, Image.translate/4, Image.meme/3, Image.from_binary/2, Image.from_svg/2 and Image.join_bands/1 return {:error, %Image.Error{}} for an invalid argument instead of raising FunctionClauseError. Each reason is an :invalid_<argument> atom, and ten ! variants that duplicated their guard now raise Image.Error as intended rather than FunctionClauseError.

  • Image.posterize/2, Image.sepia/2, Image.gamma/2 and Image.set_orientation/2 return {:error, %Image.Error{}} for an invalid argument, where they previously raised FunctionClauseError despite each declaring {:error, error()} in its spec. The reasons are :invalid_levels, :invalid_strength, :invalid_exponent and :invalid_orientation, and the ! variants raise Image.Error.

  • Widens the specs of Image.multiply_alpha/2, Image.sepia/2 and Image.gamma/2 from float() to number() and Image.set_orientation/2 from 1..8 to integer(), matching the values their guards have always accepted and their new error clauses reject.

Fixed

  • Fix Image.warp_perspective/4, Image.straighten_perspective/3 and Image.map/3 reproducing non-opaque backgrounds incorrectly. (#216)

  • Fix Image.chroma_mask/2 and Image.find_trim/2 using an error tuple as a pixel when an :auto color lookup failed. They now propagate the error. (#219)

  • Fix Image.open!/2 putting the whole image into the error's :path and interpolating it into :message. (#218)

  • Fix the specs for Image.Math.cos/1 and Image.Math.sin/1, which omitted {:error, Image.error()}, and for eight math operators, which omitted the Vimage.t() they already accepted. All @dialyzer opt-outs and the .dialyzer_ignore_warnings file are removed. (#221)

  • Fix the :greater_than and :less_than documentation for Image.chroma_mask/2, Image.chroma_key/2 and Image.replace_color/2, which described the bounds the wrong way round in all six places they appeared. The mask covers the range between the two, so :greater_than is the lower bound and :less_than the upper. (#224)

  • Fix Image.reduce_colors/2 silently producing wrong output above 256 colors. A cast to {:u, 8} wrapped every color index above 255 back around (256 became 0, 257 became 1, and so on), so those pixels were painted with the color reached by the wraparound. (#229)

  • Fix Image.reduce_colors/2 raising instead of returning an error tuple, both for the ArgumentError that Scholar.Cluster.KMeans.fit/2 raises for checks it makes outside its option schema, and for the ArithmeticError it raises when given a single sample. (#229)

  • Fix Image.reduce_colors/2 raising when the image could not be converted to a tensor. (#229)

  • Fix Image.multiply_alpha/2 (formerly Image.opacity/2) and Image.fade/2 casting the scaled alpha band to uchar unconditionally, which saturated a 16-bit alpha to 255 and truncated a float one to 0. A half-opacity call returned a fully transparent scRGB image and a 0.4%-opacity 16-bit one, and Image.fade/2 lost its gradient on both.

  • Fix Image.compare/3 failing with composite2: images do not have same numbers of bands for any image that is not three-band sRGB. The composed difference is one band wider than the base, and libvips only infers the extra alpha band for sRGB band counts, so a greyscale comparison never composited. (#232)

  • Fix Image.compare/3 resolving :difference_color against the image before flattening it, so a two-band greyscale image resolved :red to a two-element pixel that no longer matched the one-band difference. (#232)

  • Breaking: Fix the :rmse metric of Image.compare/3, which scales the error by the range of the band format and so returned about 1.0e-9 for a float image and raised CaseClauseError for a signed one. Float formats now return {:error, %Image.Error{reason: :unsupported_metric}} and signed formats are scaled like unsigned ones. (#232)

  • Breaking: Fix the :ae metric of Image.compare/3, the default, counting a pixel as different only when its first band differed, so two images differing solely in the blue band compared as an exact match. Any band differing now counts. (#232)

  • Fix Image.compare/3 highlighting a difference in the wrong colour when it was confined to some bands: the difference was a per-band condition, so a blue-only change came out dark grey and a Lab one lost its a and b bands. The colour is now applied wherever the pixel differs, with the mask as the overlay's alpha. (#232)

  • Fix Image.compare/3 under-weighting the difference mask for :lab and :lch images. Each band's difference is now a fraction of that band's own range before the largest is taken, so L is measured against 0..100, a and b against ±128 and LCH's h against 0..360, rather than every band against one range. (#232)

  • Fix Image.compare/3 inverting its difference mask for a CMYK image, where a zero difference is no ink and so converted to white and to full opacity, blanking the background. The mask is now the largest absolute difference across the bands, which is zero for an unchanged pixel in every interpretation. (#232)

  • Fix Image.compare/3 writing an 8-bit difference mask into the alpha band of a 16-bit image, which left the highlight at 0.4% opacity and invisible. (#232)

  • Fix Image.join_bands/1 raising ArgumentError for a list holding anything other than an image. Its guard checked only that the argument was a list, so the contents reached vips_bandjoin unvalidated.

  • Fix Image.resize/3's guard, which tested scale >= 0 without is_number/1, so a string, atom or list sorted above every number, passed the guard and raised ArgumentError from libvips. It now returns {:error, %Image.Error{reason: :invalid_scale}}.

  • Fix Image.drop_shadow/2 building its shadow and canvas as 8-bit sRGB whatever the source interpretation, so a 16-bit shadow saturated to fully opaque, an scRGB one returned an alpha of 127 in a 0.0..1.0 band, and a CMYK one lost a band. It now composites in the source's own format and returns the interpretation, band format and band count it was given.

Removed

  • Breaking: Removes Image.Pixel.transparency/1, Image.Pixel.max_opacity/0 and Image.Pixel.min_opacity/0. Use Image.Pixel.alpha_for/2 for a value to write into an image's alpha band, or Image.Pixel.opacity_fraction/1 for the opacity itself. (#231)

  • Breaking: Removes the t:Image.transparency/0 and t:Image.Pixel.transparency/0 types. Use t:Image.Pixel.opacity/0, which is now the only opacity type. (#231)

  • Breaking: Removes the :alpha option of Image.Pixel.to_pixel/3 and the {color, alpha: alpha} background form. Use :opacity and {color, opacity: opacity}, which are the same options under new names. (#231)

  • Breaking: Removes :none as an opacity, though not as a color. Use :transparent instead, which it was a synonym for. (#231)

  • Breaking: Removes Image.Options.WarpPerspective, replaced by Image.Options.Mapim. (#216)

  • Breaking: Removes Image.Options.Meme.validate_options/1 and Image.Draw.maybe_add_alpha/2. (#220)

  • Breaking: Removes the Image.Error tuple constructors. raise Image.Error, {:enoent, path} and raise Image.Error, {message, path} now fall through to the catch-all clause. (#218)

  • Breaking: Removes the :sigma and :min_amplitude options from Image.chroma_mask/2, Image.chroma_key/2 and Image.replace_color/2. They were accepted and validated, but never read by any code path. (#224)