genmix 1.0.5 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # 🎨 GenMix
2
2
 
3
- AI-powered image generator using Google Gemini API. Supports image generation from text prompts and image modification with reference images.
3
+ AI-powered image generator supporting Google Gemini and Fal Nano Banana 2. Supports image generation from text prompts and image modification with reference images (Gemini).
4
4
 
5
5
  ## Features ✨
6
6
 
@@ -30,8 +30,11 @@ Create a `.env` file in your project root:
30
30
 
31
31
  ```env
32
32
  GEMINI_API_KEY=your_api_key_here
33
+ FAL_API_KEY=your_fal_api_key_here
33
34
  ```
34
35
 
36
+ `GEMINI_API_KEY` is used with provider `gemini` and `FAL_API_KEY` is used with provider `fal`.
37
+
35
38
  ## Basic Usage
36
39
 
37
40
  ### The Power of GenMix: Multiple References & Chainable API
@@ -51,6 +54,26 @@ const result = await generator
51
54
  await generator.save({ filename: 'composite-result' });
52
55
  ```
53
56
 
57
+ ### Provider Selection (Gemini or Fal)
58
+
59
+ ```javascript
60
+ import { GeminiGenerator, FalGenerator } from 'genmix';
61
+
62
+ const gemini = new GeminiGenerator({ apiKey: process.env.GEMINI_API_KEY });
63
+ const fal = new FalGenerator({ apiKey: process.env.FAL_API_KEY });
64
+
65
+ await gemini.flash().generate('A cinematic portrait with dramatic lighting');
66
+ await fal.generate('A cinematic portrait with dramatic lighting', {
67
+ numberOfImages: 1,
68
+ quality: '1K',
69
+ aspectRatio: '1:1'
70
+ });
71
+ ```
72
+
73
+ Fal models available in this integration:
74
+ - `flash` (or `banana2`) -> `fal-ai/nano-banana-2/edit` (image-to-image editing)
75
+ - `pro` (or `banana-pro`) -> `fal-ai/nano-banana-pro/edit` (image-to-image editing)
76
+
54
77
  ### Model Selection
55
78
 
56
79
  You can easily switch between the Pro and Flash models using chainable methods:
@@ -134,6 +157,13 @@ new GeminiGenerator({
134
157
  })
135
158
  ```
136
159
 
160
+ ```javascript
161
+ new FalGenerator({
162
+ apiKey: string, // Your Fal API key (required)
163
+ modelId: string // Optional: FalGenerator.MODELS.BANANA_2 or BANANA_PRO_EDIT
164
+ })
165
+ ```
166
+
137
167
  ### Model Selection Methods
138
168
 
139
169
  ```javascript
@@ -142,6 +172,15 @@ generator.flash() // Switches to the gemini-3.1-flash-image-preview model
142
172
  ```
143
173
  Both methods are chainable and return the generator instance.
144
174
 
175
+ Fal generator model methods:
176
+
177
+ ```javascript
178
+ fal.banana2() // fal-ai/nano-banana-2/edit (image editing)
179
+ fal.bananaPro() // fal-ai/nano-banana-pro/edit (image editing)
180
+ fal.pro() // alias of bananaPro()
181
+ fal.flash() // alias of banana2()
182
+ ```
183
+
145
184
  ### Reference Methods
146
185
 
147
186
  You can also use chainable methods to add one or multiple reference images before calling `generate()`:
@@ -151,6 +190,8 @@ generator.addReference(image, description) // Adds a reference image (path, URL,
151
190
  generator.clearReferences() // Removes all queued reference images
152
191
  ```
153
192
 
193
+ For `fal` (`flash` and `pro`), references can be URL, data URI, local file path, or Buffer.
194
+
154
195
  ### generate() Method
155
196
 
156
197
  ```javascript
@@ -166,6 +207,8 @@ await generator.generate(prompt, options)
166
207
  | `options.numberOfImages` | number | Number of images to generate | 1 |
167
208
  | `options.quality` | string | Quality: '1K', '2K', '4K' | - |
168
209
  | `options.aspectRatio` | string | Aspect ratio: '1:1', '16:9', '4:3', etc. | - |
210
+ | `options.width` | number | Final output width in pixels (requires `height`) | - |
211
+ | `options.height` | number | Final output height in pixels (requires `width`) | - |
169
212
 
170
213
  ### save() Method
171
214
 
@@ -203,6 +246,25 @@ await generator.save({ filename: 'my-image' });
203
246
  await generator.save();
204
247
  ```
205
248
 
249
+ ### Smart target size in library mode (non-CLI)
250
+
251
+ You can request high generation quality and still force an exact final output size directly in `generate()`:
252
+
253
+ ```javascript
254
+ const generator = new GeminiGenerator();
255
+
256
+ await generator.generate('App icon, flat minimal style', {
257
+ quality: '4K', // generation quality (independent)
258
+ width: 400,
259
+ height: 400
260
+ });
261
+
262
+ // width/height resize is automatically applied on save()
263
+ await generator.save({ filename: 'icon-400x400', extension: 'png' });
264
+ ```
265
+
266
+ If you also pass `aspectRatio`, it must match the ratio derived from `width`/`height`.
267
+
206
268
  **Note:**
207
269
  - When multiple images are generated and a custom filename is provided, they will be saved as `filename_0.jpg`, `filename_1.jpg`, etc.
208
270
  - The method uses Sharp for image conversion, supporting high-quality format conversion
@@ -302,7 +364,8 @@ try {
302
364
  genmix/
303
365
  └── generators/
304
366
  │ ├── BaseGenerator.js # Base class with utilities
305
- └── GeminiGenerator.js # Gemini API implementation
367
+ ├── GeminiGenerator.js # Gemini API implementation
368
+ │ └── FalGenerator.js # Fal Nano Banana 2 implementation
306
369
  ├── demo/
307
370
  │ ├── example.js # Basic examples
308
371
  │ └── example-translation.js # Translate image
@@ -330,10 +393,131 @@ genmix/
330
393
 
331
394
  4. **Result Caching**: Images are automatically saved with unique hash based on the prompt
332
395
 
396
+ ## CLI Usage
397
+
398
+ ### Global CLI Installation
399
+
400
+ Install GenMix globally to use it from the command line:
401
+
402
+ ```bash
403
+ npm install -g genmix
404
+ ```
405
+
406
+ ### First run and API key persistence
407
+
408
+ If no API key is available, the CLI asks for it on first use and saves it to:
409
+
410
+ ```text
411
+ ~/.genmix/config.json
412
+ ```
413
+
414
+ You can set or update it explicitly anytime:
415
+
416
+ ```bash
417
+ genmix --config
418
+ ```
419
+
420
+ API key resolution order in CLI:
421
+ 1. Provider-specific environment variable (`GEMINI_API_KEY` or `FAL_API_KEY`)
422
+ 2. Saved config (`~/.genmix/config.json`) using `geminiApiKey`/`apiKey` or `falApiKey`
423
+ 3. Interactive prompt (then persisted)
424
+
425
+ ### Basic CLI commands
426
+
427
+ ```bash
428
+ # Show help
429
+ genmix --help
430
+
431
+ # Generate from prompt
432
+ genmix "A futuristic city with flying cars, cyberpunk style"
433
+
434
+ # Generate multiple images
435
+ genmix "A cozy cabin in winter" -n 2 -q 2K -r 16:9 -m flash
436
+
437
+ # Use Fal Nano Banana 2 edit (flash) with reference
438
+ genmix "Restyle this room with warm sunset mood" --provider fal -m flash --ref "./room.jpg" -n 2 -q 2K -r 16:9
439
+
440
+ # Use Fal Nano Banana Pro (edit) with reference
441
+ genmix "make this scene cinematic" --provider fal -m banana-pro --ref "https://example.com/input.png"
442
+ ```
443
+
444
+ ### Output file path or directory
445
+
446
+ `--output` accepts either:
447
+ - a directory path, or
448
+ - a full output file path (including filename + extension)
449
+
450
+ ```bash
451
+ # Save to a directory (auto-generated hash filename)
452
+ genmix "Watercolor fox logo" --output ./output
453
+
454
+ # Save to exact file path and filename
455
+ genmix "Watercolor fox logo" --output ./output/logo-fox.png
456
+ ```
457
+
458
+ ### Smart target size (independent from generation quality)
459
+
460
+ You can ask the model for high generation quality (for example `4K`) and still force a final exact output size.
461
+
462
+ When you pass target dimensions, GenMix CLI:
463
+ 1. Derives the generation ratio automatically (for example `400x400` -> `1:1`, `1920x1080` -> `16:9`)
464
+ 2. Generates using your selected quality (`1K`, `2K`, or `4K`)
465
+ 3. Resizes the final image to the exact dimensions you requested
466
+
467
+ ```bash
468
+ # Ask for 4K quality, deliver exact 400x400 output
469
+ genmix "app icon, flat minimal style" -q 4K --width 400 --height 400 --output ./output/icon.png
470
+ ```
471
+
472
+ If you also pass `--ratio`, it must match the derived ratio from the target size.
473
+
474
+ ### References with optional text description
475
+
476
+ Use `--ref <path:text>` to add reference images with optional guidance text:
477
+
478
+ ```bash
479
+ # Reference path only
480
+ genmix "Restyle this room" --ref ./room.jpg
481
+
482
+ # Reference path + description
483
+ genmix "Restyle this room" --ref "./room.jpg:keep composition and camera angle"
484
+
485
+ # Multiple references with descriptions
486
+ genmix "Create product ad scene" \
487
+ --ref "./product.png:use as main subject" \
488
+ --ref "./bg.jpg:use as background mood"
489
+
490
+ # References for fal models (URL, data URI, or local path)
491
+ genmix "Edit this image for a magazine look" \
492
+ --provider fal -m flash \
493
+ --ref "./photo.png"
494
+ ```
495
+
496
+ ### CLI options
497
+
498
+ ```text
499
+ -n, --number <N> Number of images (default: 1)
500
+ -q, --quality <1K|2K|4K> Image quality (default: 1K)
501
+ -p, --provider <gemini|fal> Provider (default: gemini)
502
+ -r, --ratio <ratio> Aspect ratio (default: 1:1 for gemini, auto for fal)
503
+ -m, --model <...> gemini: pro|flash (default: flash)
504
+ fal: pro|flash (aliases: banana-pro|banana2|2, default: flash)
505
+ -o, --output <path> Output directory or full output file path
506
+ -f, --format <format> Output format when output is a directory (default: jpg)
507
+ --width <px> Final output width in pixels (requires --height)
508
+ --height <px> Final output height in pixels (requires --width)
509
+ --ref <path[:text]> Reference image (path/URL/data URI); for URL descriptions use URL::description
510
+ --no-sharp Save raw model bytes without Sharp conversion (disables resizing)
511
+ --config Set/update persisted API key
512
+ --help Show help
513
+ ```
514
+
333
515
  ## Additional Resources
334
516
 
335
517
  - [Code Examples](./demo/)
336
518
  - [Google Gemini API Documentation](https://ai.google.dev/)
519
+ - [Fal Nano Banana 2 Edit Documentation](https://fal.ai/models/fal-ai/nano-banana-2/edit/api)
520
+ - [Fal Nano Banana Pro Edit Documentation](https://fal.ai/models/fal-ai/nano-banana-pro/edit/api)
337
521
 
338
522
  ## License
339
523