img_crop_lib 0.0.1
img_crop_lib: ^0.0.1 copied to clipboard
A comprehensive Flutter image editing package supporting mobile and web platforms with features like cropping, filters, drawing, and more.
Image Crop Library for Flutter #
A comprehensive image editing library for Flutter that provides a rich set of features for image manipulation, including cropping, filters, drawing, stickers, and background removal.
Features #
- 🖼️ Image Cropping: Interactive cropping with aspect ratio support
- 🎨 Drawing Tools: Freehand drawing, shapes, and text annotations
- 😀 Stickers & Emoji: Add and manipulate stickers and emoji
- ⚡ Filters & Effects: Built-in filters and adjustable effects
- 🎯 Background Removal: Simple background removal using chroma key or luminance
- 🚀 Platform Optimizations: Native performance optimizations where available
- 🔄 Undo/Redo: Full operation history support
- 📱 Responsive Design: Works across all screen sizes
- 🎛️ Fine Controls: Precise adjustment of brightness, contrast, and more
Installation #
Add this to your package's pubspec.yaml
file:
dependencies:
img_crop_lib: ^1.0.0
Basic Usage #
import 'package:img_crop_lib/img_crop_lib.dart';
// Create a basic image editor widget
Widget build(BuildContext context) {
return ImageEditorWidget(
initialImageBytes: myImageBytes, // Your image bytes
onEditingComplete: (Uint8List editedImageBytes) {
// Handle the edited image
},
);
}
Advanced Usage #
Custom Configuration #
final config = EditorConfig(
theme: EditorTheme(
backgroundColor: Colors.black,
controlsColor: Colors.white,
selectionColor: Colors.blue,
cropGridColor: Colors.white.withOpacity(0.5),
cropGridStrokeWidth: 1,
),
showCropGrid: true,
showRotateControl: true,
showFlipControls: true,
);
ImageEditorWidget(
config: config,
initialImageBytes: myImageBytes,
onEditingComplete: handleEditedImage,
);
Direct API Usage #
final editor = ImageEditor();
// Load an image
await editor.loadImage(myImageBytes);
// Apply operations
await editor.crop(cropRect);
await editor.rotate(90);
await editor.adjustColors(
brightness: 0.1,
contrast: 0.2,
saturation: 0.1,
);
// Apply a filter
await editor.applyPresetFilter('sepia');
// Remove background
await editor.removeBackground(
targetColor: Colors.green.value,
tolerance: 0.3,
);
// Export the result
final editedBytes = await editor.export(
format: ImageFormat.png,
quality: 90,
);
// Clean up
editor.dispose();
Drawing and Annotations #
// Using the DrawingCanvas
DrawingCanvas(
drawingManager: drawingManager,
onElementAdded: (element) {
// Handle new drawing element
},
onDrawingChanged: () {
// Handle drawing changes
},
);
// Adding text
final textElement = DrawText(
text: 'Hello World',
position: Offset(100, 100),
style: TextStyle(
color: Colors.red,
fontSize: 20,
fontWeight: FontWeight.bold,
),
);
drawingManager.addElement(textElement);
Stickers and Emoji #
// Add a sticker
final sticker = StickerElement(
emoji: '😀',
offset: Offset(100, 100),
scale: 1.0,
rotation: 0.0,
);
StickerOverlay(
stickers: [sticker],
onStickersChanged: (stickers) {
// Handle sticker changes
},
);
Platform Optimizations #
The library includes platform-specific optimizations that automatically use native image processing when available:
// Check for native support
final hasNativeSupport = await PlatformHandler.hasNativeSupport;
// Use optimized processing
final processedImage = await image.processOptimized(
operation: 'blur',
params: {'sigma': 5.0},
);
Error Handling #
The library provides comprehensive error handling:
try {
await editor.crop(rect);
} on ValidationError catch (e) {
// Handle validation errors (invalid parameters)
print('Validation error: ${e.message}');
} on OperationError catch (e) {
// Handle operation errors (processing failures)
print('Operation failed: ${e.message}');
} on ImageEditorException catch (e) {
// Handle other editor errors
print('Editor error: ${e.message}');
}
Contributing #
Contributions are welcome! Please see our contributing guide for details.
License #
This project is licensed under the MIT License - see the LICENSE file for details.