Created
April 14, 2011 14:56
-
-
Save mrdoob/919645 to your computer and use it in GitHub Desktop.
Create 2-sided image (color|alpha) out of a RGBA image
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
from PIL import Image | |
import glob, os | |
scale = 0.5 | |
for infile in glob.glob( "*.png" ): | |
file, ext = os.path.splitext( infile ) | |
im = Image.open( infile ) | |
im = im.resize( ( int( im.size[ 0 ] * scale ), int( im.size[ 1 ] * scale ) ) ) | |
im2 = Image.new( "RGB", ( im.size[ 0 ] * 2, im.size[ 1 ] ) ) | |
im2.paste( im, ( 0, 0, im.size[ 0 ], im.size[ 1 ] ) ) | |
im2.paste( im.split()[ 3 ], ( im.size[ 0 ], 0, im.size[ 0 ] * 2, im.size[ 1 ] ) ) | |
im2.save( file + "_alpha.png", "PNG" ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment