PIL question

Tim Eichholz phowl.mouth at gmail.com
Mon Apr 5 16:15:39 EDT 2010


I'm trying to cut a BMP with 80 adjacent frames down to 40 using the
Image.copy and .paste functions but I'm getting error "ValueError:
images do not match" on the paste line.

Here is the source ---
import sys
from PIL import Image

if len(sys.argv) == 2:
	file = sys.argv[1]
else:
	print "Usage: python rotate.py image.bmp"
	exit

print "Loading image "+file
image = Image.open(file)
if image:
	print "Successful"
else:
	print "Something didn't work out right."

cols = []

size = image.size
framew = int(raw_input("Frame width: "))
frameh = int(raw_input("Frame height: "))
ncols = size[0]/framew

print str(ncols)+" Columns, "+str(size[1]/frameh)+" Rows\n"

c = 1
while c <= ncols:
	cols += [image.crop((framew*c, 0, frameh*(c+1), frameh*(c+1)))]
	c += 1

print "New image size "+str(framew*ncols/2)+"x"+str(frameh)
print "Resizing image, could take a minute..."
newimage = image.resize(((framew*(ncols/2)), frameh), Image.NEAREST)
print "Image resized. Starting rotation loop."

f = 0
while f < (framew*(ncols/2)):
	if f%2 == 0:
		print "Pasting at "+str(f*framew)+"x0 to "+str(f*framew+framew)
+"x192"
		newimage.paste(cols[f], (f*framew, 0, (f*framew)+192, 192))
	f += 1

newimage.save('NEWIMAGE.BMP')



More information about the Python-list mailing list