[Image-SIG] bounce animation of an image

Astan Chee astan.chee at al.com.au
Mon Aug 3 03:32:49 CEST 2009


Hi,
I have a script that takes an image and makes it looks like it 
"bounces". Here it is:

import Image

def saveImg(p,pos):
    im = Image.open("new_logo.jpg")

    name = "new_logo." + str(p).zfill(4) + ".jpg"
    om = Image.new(im.mode,(im.size[0],im.size[1]))
    box = (0,pos,im.size[0],im.size[1])
    region = im.crop(box)
    nbox = (0,0,im.size[0],im.size[1]-pos)
    om.paste(region,nbox)
    om.save(name,"JPEG")
   

maxheight = 5.0
ratio = 2/3.
rate = 8.0
limit = 1

pos = 0
c = maxheight
p = 0
while c > limit:
    steps = round(rate/2.)
    leng = c/steps  
    for i in range(int(steps)):
        saveImg(p,pos)
        pos+=leng
        p+=1
    for i in range(int(steps)):
        saveImg(p,pos)
        pos-=leng
        p+=1
    c=c*ratio
   
But it keeps failing with a "ValueError: images do not match" when I do 
the pasting. What am I doing wrong?
Thanks for any help.
Cheers
Astan


More information about the Image-SIG mailing list