Skip to content

Instantly share code, notes, and snippets.

@mrdoob
Created April 14, 2011 14:56
Show Gist options
  • Save mrdoob/919645 to your computer and use it in GitHub Desktop.
Save mrdoob/919645 to your computer and use it in GitHub Desktop.
Create 2-sided image (color|alpha) out of a RGBA image
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