I'm looking for something that can generate a magazine cover with a image and I can add some content highlights on it. What's the best library to do this job? Is it PIL? or imagemagick?
I'm looking for something that can generate a magazine cover with a image and I can add some content highlights on it. What's the best library to do this job? Is it PIL? or imagemagick?
I'm surprised that you want to design a magazine cover programmatically, rather than with a GUI like Photoshop, Illustrator, Gimp, or Inkscape. But, assuming that you do, I think the easiest way would be to use Python to construct an SVG image. SVG is vector based (line positions can be modified after they have been made) and human-readable XML, so you can alternate between auto-generating graphics in Python and editing them by hand in Inkscape. Python has good built-in and third-party tools for manipulating XML, for which SVG is just a special case.
Generating an image programmatically will probably involve a lot of trial-and-error, so I recommend setting yourself up with an interactive viewer. Here's a simple one using GTK (e.g. in Ubuntu, apt-get install python-rsvg python-cairo
):
import cairo
import rsvg
import gtkclass Viewer(object):def __init__(self):self.string = """<svg width="800" height="600"></svg>"""self.svg = rsvg.Handle(data=self.string)self.win = gtk.Window()self.da = gtk.DrawingArea()self.win.add(self.da)self.da.set_size_request(800, 600)self.da.connect("expose-event", self._expose_cairo)self.win.connect("destroy", self._destroy)self.win.show_all()self.win.present()def _expose_cairo(self, win, event):self.svg = rsvg.Handle(data=self.string)cr = self.da.window.cairo_create()self.svg.render_cairo(cr)def _destroy(self, widget, data=None):gtk.main_quit()def renderSVG(self, text):x, y, w, h = self.win.allocationself.da.window.invalidate_rect((0,0,w,h), False)self.string = text
Now you can build up graphics with commands like
viewer = Viewer() # pops up a window
import lxml.etree as etree
from lxml.builder import E as svgrectangle = svg.rect(x="10", y="10", width="80", height="80", style="fill: yellow; stroke: black; stroke-width: 2;")
circle = svg.circle(cx="70", cy="70", r="30", style="fill: red; fill-opacity: 0.5; stroke: black; stroke-width: 2;")document = svg.svg(rectangle, circle, width="100", height="100")viewer.renderSVG(etree.tostring(document)) # draws the image in the window
and save them with
open("outputFile.svg", "w").write(etree.tostring(document))
Bitmapped PNG images can be embedded in SVG by encoding them in an href:data
attribute by encoding them with Base64. That would require a long explanation, but I'm just letting you know that it's possible. Also, SVG supports all of the glossy gradients and blending effects that you'd expect on a shiny magazine cover, but you'll have to dig into the documentation to see how it's done.