python - Translate image using PIL -


this question has answer here:

how can translate image 5 pixels in 1 of 4 directions using pil , python. have seen can use im.transform(size, affine, data) don't know how to.

image.transform(size, method, data) method=image.affine returns copy of image affine transformation matrix (given 6-tuple (a, b, c, d, e, f)via data) has been applied. each pixel (x, y), output calculated (ax+by+c, dx+ey+f). if want apply translation, have @ c , f values of matrix.

from pil import image  img = image.new('rgb', (100, 100), 'red') = 1 b = 0 c = 0 #left/right (i.e. 5/-5) d = 0 e = 1 f = 0 #up/down (i.e. 5/-5) img = img.transform(img.size, image.affine, (a, b, c, d, e, f)) img.save('image.png') 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo