Mosaic Image Picker
A Flutter package for creating beautiful image mosaics with drag, pinch-to-zoom, and automatic image optimization. Perfect for creating photo collages and grids in your Flutter apps.
Features
✨ Easy to Use - Simple API with just one method call
📱 Mobile First - Optimized for iOS and Android
🎨 Flexible Layouts - Support for 1, 2, 3, or 4 image grids
👆 Intuitive Gestures - Drag with 2 fingers, pinch to zoom
🖼️ Auto Optimization - Automatic EXIF rotation fix and image compression
⚡ Performance - Optimized image handling for smooth user experience
🎯 Final Output - Generates a single composed image ready to save
Demo
![]() |
![]() |
![]() |
![]() |
| 2 Horizontal | 2 Vertical | 3 Vertical | 2x2 Grid |
Installation
Add this to your package's pubspec.yaml file:
dependencies:
mosaic_image_picker: ^0.0.1
Then run:
flutter pub get
Usage
Basic Example
import 'package:flutter/material.dart';
import 'package:mosaic_image_picker/mosaic_image_picker.dart';
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('Image Mosaic Creator')),
body: Center(
child: ElevatedButton(
onPressed: () async {
// Show the mosaic creator
final result = await ImageMosaicCreator.show(context);
if (result != null && result.images.isNotEmpty) {
// result.images[0] is the final optimized composed mosaic
final composedImage = result.images[0];
// Use the image as needed
print('Mosaic created: ${composedImage.path}');
}
},
child: Text('Create Mosaic'),
),
),
),
);
}
}
Dark Mode Example
final result = await ImageMosaicCreator.show(
context,
backgroundColor: Colors.black,
secondaryColor: Colors.white,
);
Custom Confirm Button
final result = await ImageMosaicCreator.show(
context,
confirmButton: FloatingActionButton(
onPressed: () {}, // Will be replaced with actual confirm action
backgroundColor: Colors.deepPurple,
child: const Icon(Icons.check),
),
backgroundColor: Colors.white,
secondaryColor: Colors.deepPurple,
);
if (result != null && result.images.isNotEmpty) {
// result.images[0] contains the final composed mosaic
print('Mosaic created successfully!');
}
Available Layouts
The package supports 5 different layout types:
| Layout | Description | Slots |
|---|---|---|
MosaicLayout.single |
Single full image | 1 |
MosaicLayout.twoHorizontal |
2 images stacked horizontally | 2 |
MosaicLayout.twoVertical |
2 images side by side | 2 |
MosaicLayout.threeVertical |
3 images stacked vertically | 3 |
MosaicLayout.fourGrid |
2x2 grid of images | 4 |
Gestures
- Tap empty slot to pick an image
- Two-finger drag to reposition image
- Pinch to zoom in/out (0.1x to 3.0x)
- Tap X button to remove an image
Image Optimization
The package automatically:
- Fixes EXIF rotation issues (images from camera)
- Resizes images to optimal dimensions (max 2560px)
- Compresses with high quality (95% JPEG)
- Reduces file size while maintaining visual quality
Advanced Usage
Accessing Layout Information
final result = await ImageMosaicCreator.show(context);
if (result != null) {
print('Layout used: ${result.layout}');
print('Number of images: ${result.images.length}');
print('Positions: ${result.positions}');
print('Scales: ${result.scales}');
}
Manual Image Optimization
import 'package:mosaic_image_picker/mosaic_image_picker.dart';
// Optimize a single image
XFile optimizedImage = await MediaOptimizationService.optimizeImage(originalImage);
// Fix EXIF rotation
File fixedImage = await MediaOptimizationService.fixExifRotation(imagePath);
Platform Support
| Platform | Supported |
|---|---|
| Android | ✅ |
| iOS | ✅ |
| Web | ⚠️ Limited (no video support) |
| Desktop | ❌ Not tested |
Permissions
iOS (Info.plist)
<key>NSPhotoLibraryUsageDescription</key>
<string>We need access to your photos to create mosaics</string>
<key>NSCameraUsageDescription</key>
<string>We need access to your camera to take photos</string>
Android (AndroidManifest.xml)
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA"/>
For Android 13+, also add:
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
Dependencies
This package uses the following dependencies:
image_picker- For picking images from gallery/cameraimage- For image processing and optimizationpermission_handler- For requesting permissionspath_provider- For temporary file storageexif- For reading and fixing EXIF datavideo_compress,video_player,video_thumbnail- For optional video supportdevice_info_plus- For Android version detection
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Created with ❤️ for the Flutter community
Changelog
See CHANGELOG.md for a list of changes.
Issues and Feedback
Please file issues, bugs, or feature requests in our issue tracker.
Support
If you find this package useful, please consider:
- ⭐ Starring the repository
- 🐛 Filing issues and feature requests
- 📝 Contributing to the codebase
- 📣 Sharing with other Flutter developers



