Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create static graphics files (png, gif, jpg) using Ruby or Python [closed]

I'd like to create a graphic image on the fly based on user input, and then present that image as a PNG file (or jpg or gif if necessary, but PNG is preferred).

This is actually for an astrology application; what I'd like to do is generate the chart in PNG for display.

Python or Ruby is fine; in fact, the library available may determine the language I use.

Update

Here's an example image:
Example horoscope graphic chart

like image 465
Charlie Martin Avatar asked Mar 24 '09 04:03

Charlie Martin


2 Answers

Maybe a vectorial format is better suited for your needs, but is hard to tell without having a concrete example of what you'd like to get.

For example, if the images are all alike, you could create a SVG base image with Inkscape, then edit it programmaticaly from Python or Ruby (either by editing the text or using a XML library) and finally export it to PNG.


Update: After seeing the example image, I think SVG would be the most convenient choice. A SVG image is an XML file that basically says "draw a circle from here to here, write the string '13º52' there", etc. You could draw a unique base chart in Inkscape and have your program just adding the lines and symbols for each case. Finally you export to PNG.

The advantages are: easier for you to draw, the image is fully scalable, you can change the styling just by editing a property ("make all lines wider", "change all text to Arial", "paint the background blue"), you can export to any format without losing quality, and I think it's more mantainable.

like image 88
Roberto Bonvallet Avatar answered Oct 23 '22 15:10

Roberto Bonvallet


In Python, you'd typically use PIL, the Python Image Library. I've never used PIL for anything beyond the simplest tasks, so I can't say how well it performs in practice.

I'd start digging into PIL with a look at its documentation, particularly the documentation for the draw module.

like image 43
kquinn Avatar answered Oct 23 '22 14:10

kquinn