Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

PIL/Pillow is a raster image processor, a.k.a. bitmap image processor and incapable of generating vector output such as SVG.

However, if you really just need a 500x500 black rectangle with some simple text, you can write that yourself without any library dependencies:

#!/usr/bin/env python3
# Create SVG string - more examples here https://www.w3schools.com/graphics/svg_intro.asp
svg = """<?xml version="1.0"?><svg xmlns="http://www.w3.org/2000/svg" width="500" height="500">
  <rect width="500" height="500" style="fill:rgb(0,0,0)" />
  <text x="20" y="200" fill="yellow">Some simple text.</text>
# Write to a text file
with open('image.svg', 'w') as f:
    f.write(svg)

The file contents obviously look like the string svg in the code, and you can convert it to a PNG for viewing with ImageMagick like this:

magick image.svg result.png

You could equally use your web browser to visualise it by clicking on File->Open File and selecting image.svg

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.