image_pixels_plus 1.0.0 copy "image_pixels_plus: ^1.0.0" to clipboard
image_pixels_plus: ^1.0.0 copied to clipboard

Read the width/height and the color of any pixel of an image — raster or SVG. A modern, Flutter-web-compatible fork of image_pixels.

1.0.0 #

Initial release of the fork. image_pixels_plus keeps the original image_pixels API and fixes/modernizes it:

API renamed to match the package #

  • ImagePixelsImagePixelsPlus and ImagePixelsSvgImagePixelsPlusSvg.
  • ImgDetails is now self-sufficient: pixelColorAt(x, y) and pixelColorAtAlignment(alignment) are real methods instead of nullable function-typed fields — drop the ! from your builder code, e.g. img.pixelColorAt!(x, y) becomes img.pixelColorAt(x, y). pixelColorAtAlignment now takes a non-nullable Alignment.
  • ImagePixelsPlus.debugByteDataExtractor is now annotated @visibleForTesting, so the analyzer flags accidental production usage.

Resource-leak fixes #

  • Fixed a native-memory leak where ImageInfo objects delivered by the image stream were never disposed. Flutter hands every listener an owned clone, so each delivery leaked a ui.Image handle — per frame for animated GIF/WebP, and again on provider switches, stale deliveries and unmounting. Handles are now owned and disposed correctly in all those paths. (Regression tests prove the leak existed by counting open handles via ui.Image.debugGetOpenHandleStackTraces.)
  • Fixed a leaked Picture on every SVG rasterization (rasterizeSvg) and on the web fallback path of extractRawRgbaBytes; both are now disposed even when rasterization fails.

Performance #

  • New lazyBytes flag on all ImagePixelsPlus constructors: skips the eager full-image byte extraction (width × height × 4 bytes + GPU→CPU readback) until the first pixel read is actually performed. Ideal when you only need dimensions or read pixels rarely.
  • Redundant re-extraction is skipped when a stream re-delivers an identical frame; pixelColorAtAlignment no longer allocates a Size per call.
  • New optional cacheKey parameter on ImagePixelsPlusSvg: gives custom BytesLoaders (which may not implement value equality) a stable identity so ancestor rebuilds don't trigger full SVG parse + rasterization cycles. Built-in flutter_svg loaders already compare by value and need nothing.

API hardening #

  • rasterizeSvg now validates its arguments at runtime (release mode too): exactly one source must be given and dimensions must be positive; violations throw ArgumentError instead of relying on asserts or crashing with a null-check error.

Flutter web fix #

  • Fixed Failed to encode the image into bytes: pixel extraction now handles web renderers that cannot read back the pixels of a decoded image by re-rasterizing it into a fresh engine-owned surface as a fallback.
  • Extraction failures degrade gracefully (pixel reads return the defaultColor) instead of crashing with unhandled exceptions.

SVG support #

  • New ImagePixelsPlusSvg widget (asset, string, bytes or any vector graphics BytesLoader) that rasterizes an SVG and gives you the regular pixel-reading API, on all platforms including web.
  • New rasterizeSvg() function to rasterize an SVG to a ui.Image yourself.
  • Rasterization starts in didChangeDependencies() (not initState()), since it needs inherited widgets like theme/localization through the context.

API additions #

  • ImagePixelsPlus.uiImage() constructor for already-decoded ui.Images (caller keeps ownership).
  • Optional errorBuilder, called when the image fails to load; previously errors were silently swallowed.
  • ImgDetails.hasPixelData to distinguish "image available" from "pixels readable".

Refactoring / fixes #

  • Replaced usage of the protected loadImage() method with the public ImageProvider.resolve() API.
  • Proper listener lifecycle: listeners are removed on dispose and on provider changes; a generation counter discards stale async results.
  • Fixed a bug where stale pixel bytes could be indexed with new dimensions while a new image was loading (possible RangeError). Byte extraction is now atomic with dimension updates, plus defensive bounds checking.

Tooling #

  • Full test suite (24 tests): unit tests for byte extraction and SVG rasterization; widget tests for all constructors, error handling, alignment switching, resource-leak regressions (open-handle counting), extraction counting, lazy-mode behavior, same-frame deduplication, argument validation and SVG source-stability scenarios.
  • Modernized example app: single showcase file with Material 3 theming, container demo with live alignment picker, raster/SVG pixel pickers with clipboard support, and web platform support.
  • Removed the Dart-2 lints iterable_contains_unrelated_type / list_remove_unrelated_type, superseded by collection_methods_unrelated_type.
  • Stopped tracking pubspec.lock (packages don't commit lockfiles).
3
likes
160
points
66
downloads
screenshot

Documentation

API reference

Publisher

verified publisheresentis.dev

Weekly Downloads

Read the width/height and the color of any pixel of an image — raster or SVG. A modern, Flutter-web-compatible fork of image_pixels.

Repository (GitHub)
View/report issues

Topics

#image #image-processing #image-pixels #image-colors #widget

License

MIT (license)

Dependencies

flutter, flutter_svg

More

Packages that depend on image_pixels_plus