Offset (roll) image horizontally and vertically

We see here how to roll an image. That is, to shift it to the right or left without losing anything - the image effectively rolls as if the edges were joined. The same process will work in the vertical direction.

Getting ready

Use the image canary_a.jpg from the folder /constr/pics1.

How to do it...

Execute the following program noting that we need to import a module belonging to PIL called ImageChops. The Chops stands for channel operations.

# image_offset_1.py
# >>>>>>>>>>>>>>>
import Image
import ImageChops
im_1 = Image.open("/constr/pics1/canary_a.jpg")
# adjust width and height to desired size
dx = 200
dy = 300
im_2 = ImageChops.offset(im_1, dx, dy)
im_2.save("/constr/picsx/canary_2.jpg")

How it works...

The excellent guide Python Imaging Library by John Shipman written in mid 2009 does not mention ImageChops.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.163.238