[Image-SIG] adding overlay & text to many files

Stani spe.stani.be at gmail.com
Thu Jan 29 17:39:24 CET 2009

Op woensdag 14-01-2009 om 19:42 uur [tijdzone -0800], schreef Bernard
> > Phatch has already a text action which has done the hard work already as
> > well. Just start from that as a base and hack it to use a csv file as
> > input instead of a fixed text. If you have played with python and PIL
> > already, it should be not that hard.
> > 
> Thanks for the help.
> I've taken a look at the tutorial and the existing text.py action.
> I am new to Python, and have never used PIL, but it does look do-able..
> A couple of questions on the existing text action:
> 1) Is the the "cache" dict  the only recommended way to maintain state between invocations?
> 2) What is the "values" method of the Action class in the text.py file?
The values method convert relative values (given by the user) into
absolute values based on image properties (height, width, ...). For
example for a pixel value a user can enter absolute pixels, metrics (cm,
mm, ...) or a percentage. In the end we need absolute pixels to work
with PIL. So metrics are converted to pixels by multiplying with the
dpi. Percentage are calculated by multiplying with the appropriate image
property. For example for a horizontal offset of 5%, we take 5% of the
image width. The font size is based on the average of the image height
and width.

> 3) What does the "global" statement in the init() method do, and why is it there?
Phatch uses a very simple plugin mechanism. It imports all the actions
at startup. In order not to load modules which might not be used and to
keep one action limited to one file, we need a lazy import for modules
which are only necessary when executing the action. Therefore they are
grouped in an init method and global is used to make them globally

> 4) What is line 38 trying to do, and why is it in the if clause?
If no (truetype) font is given, Phatch will use the default PIL font
which AFAIK can not handle unicode (e.g. chinese characters). Therefore
text needs to be converted to ascii. Phatch choses to replace a
character with a ? if it can't be encoded.
> Also, was this file based on the Watermark code?  Many if the code comments would indicate so.
Indeed. Many actions are based on other ones. This is the fastest way to
write new actions.

>  (Running out of Ubuntu Intrepid repo)
If you start developing, please checkout phatch from the bazaar
repository (bzr lp:phatch)
> Where can I find further docs on the plug-in / action  API?
I guess you've read already:

The best is to study and understand the source of the other actions and
see them in action.
> Thank you
You're welcome!


More information about the Image-SIG mailing list