nano-banana-2-ai
v1773626.802.81
Published
Professional integration for https://nanaimg.app/
Downloads
36
Maintainers
Readme
nano-banana-2-ai
A lightweight JavaScript library for image processing and AI-powered enhancements. Provides essential tools for manipulating and improving images directly in your JavaScript environment.
Nano Banana 2 AI Image Generator
Installation
bash npm install nano-banana-2-ai
Usage Examples
Below are several practical examples demonstrating how to utilize nano-banana-2-ai in various JavaScript environments.
1. Basic Image Resizing (Browser): javascript import { resizeImage } from 'nano-banana-2-ai';
const imageElement = document.getElementById('myImage');
resizeImage(imageElement, { width: 200, height: 150 }) .then(resizedImage => { // resizedImage is a data URL representing the resized image document.getElementById('resizedImage').src = resizedImage; }) .catch(error => { console.error("Error resizing image:", error); });
2. Image Enhancement (Node.js): javascript const { enhanceImage } = require('nano-banana-2-ai'); const fs = require('fs');
fs.readFile('input.jpg', (err, data) => { if (err) { console.error("Error reading file:", err); return; }
enhanceImage(data) .then(enhancedBuffer => { fs.writeFile('output.jpg', enhancedBuffer, (err) => { if (err) { console.error("Error writing file:", err); } else { console.log("Image enhanced and saved as output.jpg"); } }); }) .catch(error => { console.error("Error enhancing image:", error); }); });
3. Converting Image to Grayscale (Browser): javascript import { grayscaleImage } from 'nano-banana-2-ai';
const imageElement = document.getElementById('colorImage');
grayscaleImage(imageElement) .then(grayscaleDataURL => { document.getElementById('grayscaleImage').src = grayscaleDataURL; }) .catch(error => { console.error("Error converting to grayscale:", error); });
4. Applying a Sepia Filter (Node.js): javascript const { sepiaFilter } = require('nano-banana-2-ai'); const fs = require('fs');
fs.readFile('input.png', (err, data) => { if (err) { console.error("Error reading file:", err); return; }
sepiaFilter(data) .then(sepiaBuffer => { fs.writeFile('sepia_output.png', sepiaBuffer, (err) => { if (err) { console.error("Error writing file:", err); } else { console.log("Sepia filter applied and saved as sepia_output.png"); } }); }) .catch(error => { console.error("Error applying sepia filter:", error); }); });
5. Getting Image Dimensions (Browser): javascript import { getImageDimensions } from 'nano-banana-2-ai';
const imageElement = document.getElementById('sourceImage');
getImageDimensions(imageElement) .then(dimensions => { console.log("Image Width:", dimensions.width); console.log("Image Height:", dimensions.height); }) .catch(error => { console.error("Error getting dimensions:", error); });
API Summary
resizeImage(image, options): Resizes an image.image: An HTMLImageElement (browser) or a Buffer/Uint8Array (Node.js).options: An object withwidthandheightproperties (numbers).- Returns: A
Promisethat resolves with a data URL (browser) or a Buffer (Node.js) representing the resized image.
enhanceImage(image): Enhances the quality of an image.image: A Buffer/Uint8Array (Node.js) or an HTMLImageElement (browser).- Returns: A
Promisethat resolves with a data URL (browser) or a Buffer (Node.js) representing the enhanced image.
grayscaleImage(image): Converts an image to grayscale.image: An HTMLImageElement (browser) or a Buffer/Uint8Array (Node.js).- Returns: A
Promisethat resolves with a data URL (browser) or a Buffer (Node.js) representing the grayscale image.
sepiaFilter(image): Applies a sepia filter to an image.image: A Buffer/Uint8Array (Node.js) or an HTMLImageElement (browser).- Returns: A
Promisethat resolves with a data URL (browser) or a Buffer (Node.js) representing the sepia-toned image.
getImageDimensions(image): Retrieves the dimensions of an image.image: An HTMLImageElement (browser) or a Buffer/Uint8Array (Node.js).- Returns: A
Promisethat resolves with an object containingwidthandheightproperties (numbers).
License
MIT
This package is part of the nano-banana-2-ai ecosystem. Explore the Nano Banana 2 AI Image Generator for advanced features and enterprise-grade tools.
