Skip to content

Google Imagen

The Google plugin provides image generation using Google’s Imagen model.

Terminal window
pnpm add @teamflojo/floimg-google
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'
}
});
ParameterTypeRequiredDescription
promptstringYesText description of the image
negativePromptstringNoWhat to avoid in the image
aspectRatiostringNo1:1, 16:9, 9:16, 4:3, 3:4 (default: 1:1)
numberOfImagesnumberNoNumber of images to generate (1-4)
personGenerationstringNoallow_adult, dont_allow
safetyFilterLevelstringNoblock_some, block_most, block_few
RatioDescription
1:1Square (default)
16:9Landscape/widescreen
9:16Portrait/vertical
4:3Standard landscape
3:4Standard portrait
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 image
const 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 save
const resized = await floimg.transform({
blob: landscape,
op: 'resize',
params: { width: 1920 }
});
await floimg.save(resized, './forest-path.png');

Get your API key from Google AI Studio.

Set the environment variable:

Terminal window
export GOOGLE_AI_API_KEY=...