将用户上传的一张照片(人物、宠物、物品、Logo/Icon)转换成一套包含4个经典动作、带有中文配文的高质量 GIF 表情包,并提供在线展示页面。整个流程分三步:静态图生成 → 动态视频生成 → GIF转换与交付。
序号动作配文文件名标识1开心挥手嗨~hi2大笑捧腹哈哈哈laugh3哭泣流泪呜呜呜cry4比心爱心爱你哦love
目标: 生成4张带有不同动作和中文配文的静态 Q 版图片。
使用 images_understand 深度分析用户上传的照片,识别主体类型:
直接基于用户上传的照片, 并发 调用 edit_images 生成4张不同的图片。
Prompt 策略: 使用高质量的英文 Prompt,强调以下关键要素:
python
edit_images(
image_edit_items=[
{
"prompt": "3D cute Q-version cartoon style, Pop Mart blind box style, chibi character, big head, waving happily, greeting warmly. Clean white background, minimalist, high quality 3D render, C4D, octane render. Text rendering: Clear, legible Chinese text '嗨~' written at the bottom. Text style: Black text with thick white outline, bold cute font, floating in front of the character. No spelling errors, no blur, sharp details.",
"base_image_file": "<用户上传的图片>",
"output_file": "imgs/sticker_01_hi.png"
},
{
"prompt": "3D cute Q-version cartoon style, Pop Mart blind box style, chibi character, big head, laughing out loud, holding belly. Clean white background, minimalist, high quality 3D render, C4D, octane render. Text rendering: Clear, legible Chinese text '哈哈哈' written at the bottom. Text style: Black text with thick white outline, bold cute font, floating in front of the character. No spelling errors, no blur, sharp details.",
"base_image_file": "<用户上传的图片>",
"output_file": "imgs/sticker_02_laugh.png"
},
{
"prompt": "3D cute Q-version cartoon style, Pop Mart blind box style, chibi character, big head, crying, tears flowing. Clean white background, minimalist, high quality 3D render, C4D, octane render. Text rendering: Clear, legible Chinese text '呜呜呜' written at the bottom. Text style: Black text with thick white outline, bold cute font, floating in front of the character. No spelling errors, no blur, sharp details.",
"base_image_file": "<用户上传的图片>",
"output_file": "imgs/sticker_03_cry.png"
},
{
"prompt": "3D cute Q-version cartoon style, Pop Mart blind box style, chibi character, big head, making heart shape with hands, love hearts around. Clean white background, minimalist, high quality 3D render, C4D, octane render. Text rendering: Clear, legible Chinese text '爱你哦' written at the bottom. Text style: Black text with thick white outline, bold cute font, floating in front of the character. No spelling errors, no blur, sharp details.",
"base_image_file": "<用户上传的图片>",
"output_file": "imgs/sticker_04_love.png"
}
]
)
输出: 4张带字图片路径:
imgs/sticker_01_hi.pngimgs/sticker_02_laugh.pngimgs/sticker_03_cry.pngimgs/sticker_04_love.png目标: 将4张静态图片转换为动态短视频。
batch_image_to_video 进行并发生成,严禁串行调用。python
batch_image_to_video(
count=4,
image_file_list=[
"imgs/sticker_01_hi.png",
"imgs/sticker_02_laugh.png",
"imgs/sticker_03_cry.png",
"imgs/sticker_04_love.png"
],
output_file_list=[
"videos/sticker_01_hi.mp4",
"videos/sticker_02_laugh.mp4",
"videos/sticker_03_cry.mp4",
"videos/sticker_04_love.mp4"
],
prompt_list=[
"Q版卡通人物开心挥手,热情打招呼,动作夸张可爱,保持文字清晰,High Quality, 1s loop",
"Q版卡通人物大笑捧腹,笑得前仰后合,保持文字清晰,High Quality, 1s loop",
"Q版卡通人物哭泣流泪,擦眼泪,保持文字清晰,High Quality, 1s loop",
"Q版卡通人物双手比心,发射爱心,保持文字清晰,High Quality, 1s loop"
],
# 强制所有视频时长为 1秒,确保快速生成
duration_list=[1, 1, 1, 1],
resolution_list=["768P"] * 4
)
输出: 4个1秒短视频路径:
videos/sticker_01_hi.mp4videos/sticker_02_laugh.mp4videos/sticker_03_cry.mp4videos/sticker_04_love.mp4目标: 将视频转换为 GIF 动图并提供展示与下载。
调用 Python 转换脚本,将视频批量转换为 GIF。
bash
python3 cookbook/script/convert_mp4_to_gif.py -i videos -o gifs --fps 10 --width 240
调用脚本生成包含所有 GIF 的 index.html 页面。
bash
python3 cookbook/script/generate_html.py
将生成的 GIF 和 HTML 页面打包部署,提供在线预览链接。
python
deploy(
dist_dir="gifs",
project_name="my-q-stickers",
project_type="Others"
)
直接在对话中返回一个包含 GIF 视窗路径的 Markdown 表格:
表情配文GIF 路径开心挥手嗨~gifs/sticker_01_hi.gif大笑捧腹哈哈哈gifs/sticker_02_laugh.gif哭泣流泪呜呜呜gifs/sticker_03_cry.gif比心爱心爱你哦gifs/sticker_04_love.gif
必须包含以下提示文案: "如果需要下载, 请点击表格里面的 GIF 路径, 到视窗的右上角进行下载"
batch_image_to_video 并发执行,严禁串行调用。步骤工具必须/可选分析原图images_understand必须生成静态图edit_images必须生成视频batch_image_to_video必须转换GIFbash (python3 convert_mp4_to_gif.py)必须生成展示页bash (python3 generate_html.py)必须部署deploy必须
text
├── imgs/
│ ├── sticker_01_hi.png
│ ├── sticker_02_laugh.png
│ ├── sticker_03_cry.png
│ └── sticker_04_love.png
├── videos/
│ ├── sticker_01_hi.mp4
│ ├── sticker_02_laugh.mp4
│ ├── sticker_03_cry.mp4
│ └── sticker_04_love.mp4
└── gifs/
├── sticker_01_hi.gif
├── sticker_02_laugh.gif
├── sticker_03_cry.gif
└── sticker_04_love.gif
sticker_{序号}_{标识}.{ext}batch_image_to_video 并发生成,不要逐个调用。images_understand 分析原图,再进行生成。