nano-banana-1
A lightweight Dart package for efficient image size reduction and basic manipulation, ideal for optimizing images for web and mobile applications. It provides simple APIs for common image processing tasks.
Installation
To use nano-banana-1 in your Dart project, add it as a dependency in your pubspec.yaml file:
yaml
dependencies:
nano_banana_1: ^1.0.0 # Replace with the latest version
Then, run dart pub get to install the package.
Usage
Here are some examples of how to use nano-banana-1:
1. Resizing an Image: dart import 'package:nano_banana_1/nano_banana_1.dart'; import 'dart:io'; import 'dart:typed_data';
Future
// Resize the image to a width of 200 pixels, maintaining aspect ratio. final Uint8List resizedImageBytes = await NanoBanana.resizeImage( imageBytes: imageBytes, width: 200, );
// Save the resized image to a new file. final File resizedFile = File('resized_image.jpg'); await resizedFile.writeAsBytes(resizedImageBytes);
print('Image resized and saved to resized_image.jpg'); }
2. Converting Image Format: dart import 'package:nano_banana_1/nano_banana_1.dart'; import 'dart:io'; import 'dart:typed_data';
Future
// Convert the image to JPEG format. final Uint8List convertedImageBytes = await NanoBanana.convertImageFormat( imageBytes: imageBytes, format: ImageFormat.jpeg, quality: 80, // JPEG quality (0-100) );
// Save the converted image to a new file. final File convertedFile = File('converted_image.jpg'); await convertedFile.writeAsBytes(convertedImageBytes);
print('Image converted to JPEG and saved to converted_image.jpg'); }
3. Compressing Image Quality: dart import 'package:nano_banana_1/nano_banana_1.dart'; import 'dart:io'; import 'dart:typed_data';
Future
// Compress the image to a quality of 60 (0-100). Lower values result in smaller file sizes. final Uint8List compressedImageBytes = await NanoBanana.compressImage( imageBytes: imageBytes, quality: 60, );
// Save the compressed image to a new file. final File compressedFile = File('compressed_image.jpg'); await compressedFile.writeAsBytes(compressedImageBytes);
print('Image compressed and saved to compressed_image.jpg'); }
4. Getting Image Dimensions: dart import 'package:nano_banana_1/nano_banana_1.dart'; import 'dart:io'; import 'dart:typed_data';
Future
// Get the dimensions of the image. final ImageDimensions dimensions = await NanoBanana.getImageDimensions(imageBytes: imageBytes);
print('Image Width: ${dimensions.width}'); print('Image Height: ${dimensions.height}'); }
Features
- Image Resizing: Resize images to specified dimensions while maintaining aspect ratio.
- Image Format Conversion: Convert between common image formats (JPEG, PNG).
- Image Compression: Reduce image file size by adjusting compression quality.
- Image Dimension Retrieval: Obtain the width and height of an image.
- Lightweight: Minimal dependencies for fast performance.
- Asynchronous Operations: Utilizes asynchronous operations for non-blocking image processing.
License
MIT License
This package is part of the nano-banana-1 ecosystem. For advanced features and enterprise-grade tools, visit: https://supermaker.ai/image/nano-banana/
Libraries
- nano_banana_1
- Provides core functionalities for interacting with the Nano Banana image service.