Created
September 14, 2014 15:29
-
-
Save felix021/1a46bb4a858bc7c07cf9 to your computer and use it in GitHub Desktop.
交换图片的左右两半
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
#coding:utf-8 | |
import sys | |
import PIL | |
from PIL import Image | |
if len(sys.argv) < 2: | |
raise Exception("bad parameter") | |
fn = sys.argv[1] | |
im = Image.open(fn) | |
width, height = im.size | |
mid = width / 2 | |
box1 = (0, 0, mid, height) | |
box2 = (mid, 0, width, height) | |
region1 = im.crop(box1) | |
region2 = im.crop(box2) | |
im1 = Image.new('RGBA', (width, height)) | |
im1.paste(region2, (0, 0)) | |
im1.paste(region1, (mid, 0)) | |
im1.save('x_' + fn) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment