Python scripting with Paint Shop Pro 8.0

Duncan Booth duncan at NOSPAMrcp.co.uk
Thu Jul 24 12:21:43 EDT 2003


Marc Wilson <marc at cleopatra.co.uk> wrote in
news:bupvhv4sgqtqlhlpvb8m05ksei86oke79u at 4ax.com: 

> Oh, and- is there a way to overwrite text onto an image?  The site is
> a house-sales site, and we want to overwrite "SOLD" across the
> thumbnail once a property is sold.  It looks like I can do this with
> the ImageDraw module, but I can't see how to replicate what we do now
> with Image Robot, which is to write "SOLD" across the image diagonally
> (using the Add Watermark feature).  Any ideas?

How about this:

from PIL import Image, ImageFont, ImageDraw, ImageChops

im = Image.open("test.jpg")
im.thumbnail((128, 128), Image.ANTIALIAS)

font = ImageFont.truetype("arial.ttf", 30)

def AddOverlay(im, origin, text, angle=-45):
    # Create an overlay with white text and subtract it from the image.
    # This effectively blacks out the area to be overlaid.
    overlay = Image.new(im.mode, im.size)
    draw = ImageDraw.Draw(overlay)
    draw.text(origin, text, (255, 255, 255), font=font)
    overlay = overlay.rotate(angle)
    stamped = ImageChops.subtract(im, overlay, 1, 0)


    # Now create a red overlay and add it to the subtracted image
    overlay = Image.new(im.mode, im.size)
    draw = ImageDraw.Draw(overlay)
    draw.text(origin, text, (255, 0, 0), font=font)
    overlay = overlay.rotate(angle)
    stamped = ImageChops.add(stamped, overlay, 1, 0)
    return stamped

stamped = AddOverlay(im, (10, 50), "SOLD!")
stamped.show()


-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?




More information about the Python-list mailing list