[Image-SIG] Web button creator script with PIL.

Joao S. O. Bueno Calligaris gwidion at mpc.com.br
Mon Jul 10 08:17:19 CEST 2006


Hi,
I just made this script wover the weekend, and would like to share it with you.

Instead of writing once more what it is about, I will just
paste the docstring bellow. :-)

Download from:
http://www.pion.com.br/~gwidion/python/dynabutton-1.2.tar.gz

WHat it can do can be seen here:
http://www.pion.com.br/~gwidion/python/dynabutton_example.png

Regards,

	JS
	-><-

The documentation:
"""
This program is Free Software - see the file LICENSE for details

Dynabutton  creates dinamic buttons for WEB or other UIs in real time.
Copyright 2006 - João S. O. Bueno Calligaris

It can be used either from command line, or as a cgi program.
The accepted parameters are:
                   button_filename     = DEFAULT_BUTTON,
                   button_text         = "OK",
                   font_file           = "VeraSeBd.ttf",
                   font_size           = 18,
                   text_color          = (255, 255, 255),
                   use_shadow          = True,
                   shadow_color        = (0, 0, 0, 192),
                   fuzzy_shadow        = None,
                   shadow_offset       = 1,
                   width               = None,
                   height              = None,
                   left_width          = None,
                   right_width         = None,
                   center_slice        = None,
                   align = CENTER

button_filename    - The filename on the server side which contains a
       template to the button that will be used. The program uses the
       left and right endings of this template as the button caps
       and copies/replicates the middle section. Over this middle
       section, it renders the button text

button_text        - The button text per se. Use utf-8 encoding
font_file          - the font file (currently  ttf files only) on the
       server side which contains the font to be used to render the text.

font_size          - the font size, in pixels
text_color         - The color to render the text. An optional 4 number
       as alpha is accepted

use_shadow         - Whether to render or not a shadow for the text
shadow_color       - the color for the shadow
fuzzy_shadow       - Whether to blur the rendered shadow or not.
shadow_offset      - shadow offset in both x and y directions relative
       to the text.

width              - Button width in pixels. Automatic if not specified.
height             - Button height in pixels. Equal to the one of the
       button template image, if not specified

left_width         - Instead of taking the template's entire left
       half as button cap, use this many pixels. The remaining pixel columns
       up to the ones that make up the right button cap will be replicated/
       resized as needed to create the middle section.

right_width        - The same as left_width, but for the right button cap

center_slice       - Explicit slice of pixel columns on the image template
       that will be replicated as the button center. If not specified, it
       it is auto computed from the left_width and right_width values. (NB,
       if those are also empty, the central pixel column is just stretched
       over to make for the central button area)

align = Text alignment. Allowed values= LEFT, CENTER, RIGHT
        (v.1.2, not implemented for command line mode - use 0,1 or 2 for now)

when used as cgi, the extra parameter "image_type" specifies which image
type will be generated. From the command line, the first parameter is the
output file name, and file_type is based on its extension.
ex.: "png", "jpeg", "gif"  -

Example of CGI usage:

<html>
Teste:
<img src="http://myhost.com/dynabutton.py?button_text=APPLE&
button_filename=botao2.png&text_color=0,48,255"style="vertical-align: middle"
/>
</html>
The various parameters are encoded in the src url!

Example for command line usage:

./dynabutton.py crewind.png  cloud.png REWIND text_color:0,0,0 left_width:15
right_width:15 display

The extra "display" parameters attempts to show the result on the screen.
Python imaging library uses the 'xv' app by default to that. You can
symbolic link another app to xv if you prefer.
"""


More information about the Image-SIG mailing list