utils/image/image_utils library

Image handling utilities: resizing, clipboard, storage, validation.

Ported from neomage/src/utils/imageResizer.ts (880 LOC), neomage/src/utils/imagePaste.ts (416 LOC), neomage/src/utils/imageStore.ts (167 LOC), neomage/src/utils/imageValidation.ts (104 LOC).

Classes

CompressedImageResult
Compressed image result.
ImageBlockWithDimensions
Image block with dimension information.
ImageDimensions
Image dimension information.
ImageUtils
Manages image handling: resizing, clipboard access, storage, and validation.
ImageWithDimensions
Image with dimensions and base64 data.
OversizedImage
Information about an oversized image.
ResizeResult
Result of resizing an image.

Enums

ImageErrorType
Error type constants for analytics.
ImageMediaType
Supported image media types.

Constants

apiImageMaxBase64Size → const int
API limit for base64-encoded image data.
imageMaxHeight → const int
imageMaxWidth → const int
Maximum image dimensions.
imageTargetRawSize → const int
Target raw size for images (before base64 encoding).
pasteThreshold → const int
Threshold in characters for when to consider text a "large paste".

Properties

imageExtensionRegex RegExp
Regex pattern to match supported image file extensions.
final

Functions

asImageFilePath(String text) String?
Clean and normalize a text string that might be an image file path.
classifyImageError(Object error) ImageErrorType
Classifies image processing errors for analytics.
createImageMetadataText(ImageDimensions dims, {String? sourcePath}) String?
Creates a text description of image metadata including dimensions and source path.
detectImageFormatFromBase64(String base64Data) ImageMediaType
Detect image format from base64 data using magic bytes.
detectImageFormatFromBuffer(Uint8List buffer) ImageMediaType
Detect image format from a buffer using magic bytes.
formatFileSize(int bytes) String
Format a file size in bytes to a human-readable string.
hashString(String str) int
Computes a simple numeric hash of a string for analytics grouping. Uses djb2 algorithm, returning a 32-bit unsigned integer.
isImageFilePath(String text) bool
Check if a given text represents an image file path.

Exceptions / Errors

ImageResizeError
Error thrown when image resizing fails and the image exceeds the API limit.
ImageSizeError
Error thrown when one or more images exceed the API size limit.