Member-only story

How to use ChatGPT to generate SVG

Amir Hachaichi
3 min readJul 22, 2023

--

ChatGPT is very good at generating text, and good enough at writing code, but when it comes to SVG generation, it is a little bit more challenging.

If you are wondering why am I using a text model to generate graphics, knowing that OpenAI also has the DALL-E model that generates realistic images from a text description, this is because I’m looking to generate vector graphics. SVG images are made up of code rather than pixels, that’s why I will use GPT-3.5. At this moment there is no model specifically made for SVG generation.

Let’s start by just asking ChatGPT to generate the SVG of a duck. After pasting the generated code inside an SVG file, here is what we get:

This image gives you an idea on the kind of output that you can expect from the large language model if you provide it with a short prompt. Unlike text generation, no details are added if you don’t ask for them.

Let’s include in the prompt that we want the SVG of a duck as seen from the left side. Here is the result:

--

--

Amir Hachaichi
Amir Hachaichi

Written by Amir Hachaichi

I am passionate about web technologies and I build web applications using javascript. Also learning Data Science and LLMs enthusiast. https://synlaunch.com

Responses (1)