name: create-svg-from-prompt description: 根据用户提示生成SVG图像或场景
环境设置
如果环境中没有安装 autotrace,请使用以下命令安装:
sudo apt update
sudo apt install git build-essential intltool imagemagick libmagickcore-dev pstoedit libpstoedit-dev autopoint
git clone https://github.com/autotrace/autotrace.git
cd autotrace
./autogen.sh
LD_LIBRARY_PATH=/usr/local/lib ./configure --prefix=/usr
make
sudo make install
核心工作流程
当用户提示模型生成图像或场景的SVG时:
用户需要图像或场景的SVG
要生成图像或场景的SVG,请使用Google Gemini和autotrace:
curl -s -X POST "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-image:generateContent" -H "x-goog-api-key: <GEMINI_API_KEY>" -H "Content-Type: application/json" -d '{ "contents": [{ "parts": [ {"text": "<IMAGE_PROMPT>"}]}]}' | grep -o '"data": "[^"]*"' | cut -d'"' -f4 | base64 --decode | autotrace -output-format svg -despeckle-level 10 -despeckle-tightness 2.0 -output-file <OUTPUT_FILE>.svg
从提示中提取的参数:
<GEMINI_API_KEY>:从环境变量“GEMINI_API_KEY”获取的Gemini API密钥<IMAGE_PROMPT>:修改用户的初始提示,将“生成SVG”等短语改为“生成图像”。不要修改提示的其余部分,也不要添加任何额外的说明或描述。<OUTPUT_FILE>:基于用户想要的图像,生成一个8-30个字符的文件名