Google Imagen
The Google plugin provides image generation using Google’s Imagen model.
Installation
Section titled “Installation”pnpm add @teamflojo/floimg-googleRegistration
Section titled “Registration”import createClient from '@teamflojo/floimg';import google from '@teamflojo/floimg-google';
const floimg = createClient();
floimg.registerGenerator(google({ apiKey: process.env.GOOGLE_AI_API_KEY}));Generate images using Imagen.
const image = await floimg.generate({ generator: 'google', params: { prompt: 'A photorealistic image of a mountain lake at sunrise', aspectRatio: '16:9' }});Parameters
Section titled “Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
prompt | string | Yes | Text description of the image |
negativePrompt | string | No | What to avoid in the image |
aspectRatio | string | No | 1:1, 16:9, 9:16, 4:3, 3:4 (default: 1:1) |
numberOfImages | number | No | Number of images to generate (1-4) |
personGeneration | string | No | allow_adult, dont_allow |
safetyFilterLevel | string | No | block_some, block_most, block_few |
Aspect Ratios
Section titled “Aspect Ratios”| Ratio | Description |
|---|---|
1:1 | Square (default) |
16:9 | Landscape/widescreen |
9:16 | Portrait/vertical |
4:3 | Standard landscape |
3:4 | Standard portrait |
Example
Section titled “Example”import createClient from '@teamflojo/floimg';import google from '@teamflojo/floimg-google';
const floimg = createClient();floimg.registerGenerator(google({ apiKey: process.env.GOOGLE_AI_API_KEY}));
// Generate a landscape imageconst landscape = await floimg.generate({ generator: 'google', params: { prompt: 'A peaceful forest path in autumn, golden leaves, soft sunlight', aspectRatio: '16:9', negativePrompt: 'people, buildings, cars' }});
// Transform and saveconst resized = await floimg.transform({ blob: landscape, op: 'resize', params: { width: 1920 }});
await floimg.save(resized, './forest-path.png');API Key
Section titled “API Key”Get your API key from Google AI Studio.
Set the environment variable:
export GOOGLE_AI_API_KEY=...See Also
Section titled “See Also”- OpenAI - DALL-E image generation
- Stability AI - Stable Diffusion models
- Generate - Core generation method