关于 fal-text-to-image
这是一款使用 fal.ai 模型根据文本提示词生成图像的参考技能,面向需要集成图像生成的开发者。它涵盖模型选择,以及尺寸、生成参数、LoRA 风格和批量生成的配置。
主要功能
- 01比较 FLUX、SDXL 和专用模型
- 02设置预设或自定义图像尺寸
- 03配置模型专属生成参数
- 04为 FLUX 应用 LoRA 风格
- 05批量生成多个图像变体
适用场景
- 01根据文字提示生成图像
- 02按速度或图像质量选择模型
- 03制作含文字或矢量风格素材
- 04批量生成不同风格的变体
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ josiahsiegel/ claude-plugin-marketplace --skill fal-text-to-image安装后在 Claude Code 中输入/fal-text-to-image确认已加载。
详细介绍
快速参考
| 模型 | 端点 | 速度 | 质量 | 成本 |
|---|---|---|---|---|
| FLUX.2 Pro | fal-ai/flux-2-pro | 中等 | 最高 | $$$ |
| FLUX.1 Dev | fal-ai/flux/dev | 中等 | 高 | $$ |
| FLUX Schnell | fal-ai/flux/schnell | 快 | 良好 | $ |
| Fast SDXL | fal-ai/fast-sdxl | 快 | 良好 | $ |
| 图像尺寸 | 预设 | 尺寸 |
|---|---|---|
| 高清方形 | square_hd | 1024x1024 |
| 横向 | landscape_16_9 | 1024x576 |
| 纵向 | portrait_16_9 | 576x1024 |
| 自定义 | { width, height } | 任意 |
| 参数 | FLUX 默认值 | SDXL 默认值 |
|---|---|---|
guidance_scale | 3.5 | 7.5 |
num_inference_steps | 28 | 25 |
num_images | 1 | 1 |
何时使用此技能
用于文本生成图像:
- 根据文本提示词生成图像
- 在 FLUX 和 SDXL 模型之间进行选择
- 配置图像尺寸和质量参数
- 使用 LoRA 模型创建自定义风格
- 批量生成多张图像
相关技能:
- 图像编辑:参见
fal-image-to-image - 模型比较:参见
fal-model-guide - API 集成:参见
fal-api-reference
fal.ai 文本生成图像模型
fal.ai 上所有文本生成图像模型的完整参考。
FLUX 模型
FLUX.1 [dev]
端点: fal-ai/flux/dev
定价: $0.025/百万像素
最适合: 高质量开源生成
这款拥有 12B 参数的 FLUX.1 模型在提供开源使用便利性的同时,也能生成出色的图像。
import { fal } from "@fal-ai/client";
const result = await fal.subscribe("fal-ai/flux/dev", {
input: {
prompt: "A serene Japanese garden with cherry blossoms, koi pond, wooden bridge, soft morning light",
image_size: "landscape_16_9",
num_inference_steps: 28,
guidance_scale: 3.5,
num_images: 1,
seed: 42,
enable_safety_checker: true,
output_format: "jpeg"
}
});
console.log(result.images[0].url);
import fal_client
result = fal_client.subscribe(
"fal-ai/flux/dev",
arguments={
"prompt": "A serene Japanese garden with cherry blossoms",
"image_size": "landscape_16_9",
"num_inference_steps": 28,
"guidance_scale": 3.5,
"num_images": 1,
"seed": 42,
"enable_safety_checker": True,
"output_format": "jpeg"
}
)
print(result["images"][0]["url"])
FLUX Schnell
端点: fal-ai/flux/schnell
定价: 单张图像成本更低
最适合: 快速迭代、预览、4 步生成
经过速度优化,仅需 4 个推理步骤。
const result = await fal.subscribe("fal-ai/flux/schnell", {
input: {
prompt: "A colorful abstract painting",
image_size: "square_hd",
num_inference_steps: 4, // Optimized for 4 steps
num_images: 1
}
});
FLUX Pro
端点: fal-ai/flux-pro
定价: 高级
最适合: 生产工作负载
const result = await fal.subscribe("fal-ai/flux-pro", {
input: {
prompt: "Professional product photography of a luxury watch",
image_size: "square_hd",
num_inference_steps: 28,
guidance_scale: 3.5
}
});
FLUX.2 [pro]
端点: fal-ai/flux-2-pro
定价: $0.03/百万像素
最适合: 最高质量、自动优化提示词
最新的 FLUX 模型,内置提示词优化功能。
const result = await fal.subscribe("fal-ai/flux-2-pro", {
input: {
prompt: "A majestic lion in the savanna at golden hour",
image_size: "landscape_16_9",
num_inference_steps: 28,
guidance_scale: 3.5,
// FLUX 2 Pro features
safety_tolerance: "2", // 1-6, higher = more permissive
raw: false // Set true to disable prompt enhancement
}
});
FLUX.2 Pro 专属参数:
safety_tolerance:1-6,用于控制内容过滤的敏感度raw:布尔值,设为true可禁用自动提示词优化
FLUX LoRA
端点: fal-ai/flux-lora
最适合: 自定义训练风格和主体
将自定义 LoRA 模型应用于 FLUX 生成。
const result = await fal.subscribe("fal-ai/flux-lora", {
input: {
prompt: "A portrait in the style of <lora_trigger>",
loras: [
{
path: "https://huggingface.co/user/lora-model/resolve/main/lora.safetensors",
scale: 0.8
}
],
image_size: "portrait_4_3",
num_inference_steps: 28,
guidance_scale: 3.5
}
});
LoRA 参数:
loras:LoRA 配置数组path:LoRA 权重文件(.safetensors)的 URLscale:0-1,LoRA 效果的强度
FLUX Realism
端点: fal-ai/flux-realism
最适合: 照片级真实感图像
const result = await fal.subscribe("fal-ai/flux-realism", {
input: {
prompt: "A photorealistic portrait of a young woman, natural lighting, 85mm lens",
image_size: "portrait_4_3",
num_inference_steps: 28
}
});
FLUX Fill(扩图)
端点: fal-ai/flux-pro/v1/fill
最适合: 将图像扩展到边界之外
const result = await fal.subscribe("fal-ai/flux-pro/v1/fill", {
input: {
prompt: "Continue the landscape with mountains",
image_url: "https://example.com/partial-image.jpg",
mask_url: "https://example.com/outpaint-mask.png"
}
});
Stable Diffusion 模型
Fast SDXL
端点: fal-ai/fast-sdxl
最适合: 速度和成本效益
const result = await fal.subscribe("fal-ai/fast-sdxl", {
input: {
prompt: "A fantasy castle on a cliff, dramatic lighting",
negative_prompt: "blurry, low quality, distorted",
image_size: "landscape_16_9",
num_inference_steps: 25,
guidance_scale: 7.5,
num_images: 1,
seed: 42
}
});
SDXL 专属参数:
negative_prompt:生成时要避免的内容- 对 SDXL 而言,较高的
guidance_scale(7-12)效果更好
Stable Diffusion 3 Medium
端点: fal-ai/stable-diffusion-v3-medium
最适合: SD3 架构、良好的文本渲染效果
const result = await fal.subscribe("fal-ai/stable-diffusion-v3-medium", {
input: {
prompt: "A sign that says 'Hello World' in neon lights",
negative_prompt: "blurry, distorted text",
image_size: "square_hd",
num_inference_steps: 28,
guidance_scale: 7.0
}
});
SDXL Turbo
端点: fal-ai/sdxl-turbo
最适合: 超快的单步生成
const result = await fal.subscribe("fal-ai/sdxl-turbo", {
input: {
prompt: "A cute robot",
num_inference_steps: 1, // Single step!
guidance_scale: 0 // No guidance needed
}
});
SDXL Lightning
端点: fal-ai/fast-lightning-sdxl
最适合: 快速 4 步 SDXL
const result = await fal.subscribe("fal-ai/fast-lightning-sdxl", {
input: {
prompt: "A beautiful sunset",
num_inference_steps: 4,
guidance_scale: 1.5
}
});
专用模型
Recraft V3
端点: fal-ai/recraft-v3
最适合: 设计素材、插画、矢量风格
const result = await fal.subscribe("fal-ai/recraft-v3", {
input: {
prompt: "A minimalist logo for a tech startup, clean lines",
image_size: "square_hd",
style: "digital_illustration" // or "realistic_image", "vector_illustration"
}
});
Recraft 风格:
realistic_imagedigital_illustrationvector_illustrationicon
Ideogram
端点: fal-ai/ideogram
最适合: 图像中的文字、字体排版
const result = await fal.subscribe("fal-ai/ideogram", {
input: {
prompt: "A vintage poster with the text 'JAZZ FESTIVAL' in art deco style",
aspect_ratio: "portrait_4_3"
}
});
Playground v2.5
端点: fal-ai/playground-v25
最适合: 创意类、艺术类图像
const result = await fal.subscribe("fal-ai/playground-v25", {
input: {
prompt: "A surreal dreamscape with floating islands",
image_size: "landscape_16_9",
guidance_scale: 3.0
}
});
AuraFlow
端点: fal-ai/aura-flow
最适合: 开源的基于流的模型
const result = await fal.subscribe("fal-ai/aura-flow", {
input: {
prompt: "A magical forest with bioluminescent plants",
num_inference_steps: 28,
guidance_scale: 3.5
}
});
Kolors
端点: fal-ai/kolors
最适合: 艺术感、色彩丰富的生成
const result = await fal.subscribe("fal-ai/kolors", {
input: {
prompt: "A vibrant street market in Morocco",
image_size: "landscape_4_3"
}
});
常用参数参考
图像尺寸选项
| 预设 | 尺寸 | 宽高比 |
|---|---|---|
square | 512x512 | 1:1 |
square_hd | 1024x1024 | 1:1 |
portrait_4_3 | 768x1024 | 3:4 |
portrait_16_9 | 576x1024 | 9:16 |
landscape_4_3 | 1024x768 | 4:3 |
landscape_16_9 | 1024x576 | 16:9 |
自定义尺寸:
image_size: { width: 1920, height: 1080 }
完整参数参考
interface TextToImageInput {
// Required
prompt: string;
// Image dimensions
image_size?:
| "square" | "square_hd"
| "portrait_4_3" | "portrait_16_9"
| "landscape_4_3" | "landscape_16_9"
| { width: number; height: number };
// Generation parameters
num_inference_steps?: number; // 1-50, default varies by model
guidance_scale?: number; // 1-20, default: 3.5 (FLUX) or 7.5 (SDXL)
num_images?: number; // 1-4, default: 1
seed?: number; // For reproducibility
// Output options
output_format?: "jpeg" | "png";
enable_safety_checker?: boolean;
// SDXL-specific
negative_prompt?: string;
// FLUX 2 Pro specific
safety_tolerance?: string; // "1" to "6"
raw?: boolean; // Disable prompt enhancement
// LoRA specific
loras?: Array<{
path: string;
scale: number;
}>;
}
响应结构
interface TextToImageOutput {
images: Array<{
url: string;
width: number;
height: number;
content_type: string;
}>;
seed: number;
prompt: string;
has_nsfw_concepts?: boolean[];
timings?: {
inference: number;
};
}
模型选择指南
| 用例 | 推荐模型 | 原因 |
|---|---|---|
| 最佳质量 | fal-ai/flux-2-pro | 最新模型,可增强提示词 |
| 开源 | fal-ai/flux/dev | 12B 参数,质量出色 |
| 快速迭代 | fal-ai/flux/schnell | 4 步生成 |
| 预算有限 | fal-ai/fast-sdxl | 单张图像成本更低 |
| 超快 | fal-ai/sdxl-turbo | 单步生成 |
| 自定义风格 | fal-ai/flux-lora | 支持 LoRA |
| 图像中的文本 | fal-ai/ideogram | 专注于字体排版 |
| 设计素材 | fal-ai/recraft-v3 | 矢量风格输出 |
| 照片级真实感 | fal-ai/flux-realism | 针对真实感优化 |
最佳实践
提示词工程
对于 FLUX 模型:
- 描述要详细、具体
- 包含风格、光线和构图
- FLUX 2 Pro 会自动增强提示词(使用
raw: true可禁用) - 引导强度设为 3-4 效果最佳
对于 SDXL 模型:
- 使用负面提示词
- 更高的引导强度(7-12)有助于更好地遵循提示词
- 加入质量关键词:“high quality, detailed, 8k”
质量与速度的权衡
// Quality priority
const quality = await fal.subscribe("fal-ai/flux-2-pro", {
input: {
prompt: "...",
num_inference_steps: 28,
guidance_scale: 3.5
}
});
// Speed priority
const fast = await fal.subscribe("fal-ai/flux/schnell", {
input: {
prompt: "...",
num_inference_steps: 4
}
});
// Balance
const balanced = await fal.subscribe("fal-ai/flux/dev", {
input: {
prompt: "...",
num_inference_steps: 20,
guidance_scale: 3.5
}
});
批量生成
// Generate multiple variations
const result = await fal.subscribe("fal-ai/flux/dev", {
input: {
prompt: "A beautiful landscape",
num_images: 4,
seed: 42 // Same seed = similar outputs
}
});
// Access all images
result.images.forEach((img, i) => {
console.log(`Image ${i + 1}: ${img.url}`);
});
可复现性
// Use seed for reproducible results
const seed = 12345;
const result1 = await fal.subscribe("fal-ai/flux/dev", {
input: { prompt: "A cat", seed }
});
const result2 = await fal.subscribe("fal-ai/flux/dev", {
input: { prompt: "A cat", seed }
});
// result1 and result2 will be identical