Spaces:
Sleeping
Sleeping
Update plugins/nnbana.js
Browse files- plugins/nnbana.js +15 -5
plugins/nnbana.js
CHANGED
|
@@ -107,7 +107,15 @@ async function createGrid(imageUrls) {
|
|
| 107 |
);
|
| 108 |
|
| 109 |
const images = await Promise.all(
|
| 110 |
-
imageBuffers.map(buffer =>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
);
|
| 112 |
|
| 113 |
const count = images.length;
|
|
@@ -115,7 +123,9 @@ async function createGrid(imageUrls) {
|
|
| 115 |
|
| 116 |
let cols, rows;
|
| 117 |
if (count === 1) {
|
| 118 |
-
|
|
|
|
|
|
|
| 119 |
} else if (count === 2) {
|
| 120 |
cols = 2;
|
| 121 |
rows = 1;
|
|
@@ -129,7 +139,7 @@ async function createGrid(imageUrls) {
|
|
| 129 |
|
| 130 |
const cellSize = Math.floor(targetSize / cols);
|
| 131 |
const gridHeight = cellSize * rows;
|
| 132 |
-
const grid = await Jimp
|
| 133 |
|
| 134 |
for (let i = 0; i < count && i < 4; i++) {
|
| 135 |
const col = i % cols;
|
|
@@ -137,7 +147,7 @@ async function createGrid(imageUrls) {
|
|
| 137 |
const x = col * cellSize;
|
| 138 |
const y = row * cellSize;
|
| 139 |
|
| 140 |
-
const resized = images[i].cover(cellSize, cellSize);
|
| 141 |
grid.composite(resized, x, y);
|
| 142 |
}
|
| 143 |
|
|
@@ -206,7 +216,7 @@ const handler = async (req, res) => {
|
|
| 206 |
|
| 207 |
module.exports = {
|
| 208 |
name: 'Nano Banana',
|
| 209 |
-
description: 'AI Image Editing using
|
| 210 |
type: 'GET',
|
| 211 |
routes: ['api/AI/nanobanana'],
|
| 212 |
tags: ['ai', 'image', 'editing', 'nanobanana', 'multi-image'],
|
|
|
|
| 107 |
);
|
| 108 |
|
| 109 |
const images = await Promise.all(
|
| 110 |
+
imageBuffers.map(async buffer => {
|
| 111 |
+
const img = await Jimp.default ? Jimp.default.read(buffer) : new Promise((resolve, reject) => {
|
| 112 |
+
new Jimp(buffer, (err, image) => {
|
| 113 |
+
if (err) reject(err);
|
| 114 |
+
else resolve(image);
|
| 115 |
+
});
|
| 116 |
+
});
|
| 117 |
+
return img;
|
| 118 |
+
})
|
| 119 |
);
|
| 120 |
|
| 121 |
const count = images.length;
|
|
|
|
| 123 |
|
| 124 |
let cols, rows;
|
| 125 |
if (count === 1) {
|
| 126 |
+
const img = images[0];
|
| 127 |
+
await img.resize(targetSize, targetSize);
|
| 128 |
+
return await img.getBufferAsync(Jimp.MIME_JPEG);
|
| 129 |
} else if (count === 2) {
|
| 130 |
cols = 2;
|
| 131 |
rows = 1;
|
|
|
|
| 139 |
|
| 140 |
const cellSize = Math.floor(targetSize / cols);
|
| 141 |
const gridHeight = cellSize * rows;
|
| 142 |
+
const grid = await new Jimp(targetSize, gridHeight, 0xFFFFFFFF);
|
| 143 |
|
| 144 |
for (let i = 0; i < count && i < 4; i++) {
|
| 145 |
const col = i % cols;
|
|
|
|
| 147 |
const x = col * cellSize;
|
| 148 |
const y = row * cellSize;
|
| 149 |
|
| 150 |
+
const resized = await images[i].cover(cellSize, cellSize);
|
| 151 |
grid.composite(resized, x, y);
|
| 152 |
}
|
| 153 |
|
|
|
|
| 216 |
|
| 217 |
module.exports = {
|
| 218 |
name: 'Nano Banana',
|
| 219 |
+
description: 'AI Image Editing using Grid Plus - Edit 1-4 images with text prompts',
|
| 220 |
type: 'GET',
|
| 221 |
routes: ['api/AI/nanobanana'],
|
| 222 |
tags: ['ai', 'image', 'editing', 'nanobanana', 'multi-image'],
|