sprksh
sprksh

Reputation: 2394

Create Image through Python

I have to create a image which contains plain (one colour) background and some text on top of it. (The image would contain the title of say an article which should be saved as og image so that it shows up on sharing on facebook)

What should be the way to generate this image automatically on server? Can it be done using python or django? Can I somehow try rendering and taking screenshot? (It's an ubuntu server)

What can be the way to go forward.

Upvotes: 2

Views: 926

Answers (1)

tadamhicks
tadamhicks

Reputation: 925

Pillow is your best bet. It is imported as PIL.

Example:

from PIL import Image
from PIL import ImageDraw

img = Image.new('RGB', (500, 500))
draw = ImageDraw.Draw(img)

draw.text((0, 0),"Sample Text",(255,255,255))

img.save('sample-out.jpg')

There is also an ImageFont module that lets you get fancier with things. You'll have to figure out what you want for lettering positioning and colors.

Upvotes: 1

Related Questions