Skip to content

Instantly share code, notes, and snippets.

@mrdoob
Created April 14, 2011 14:53
Show Gist options
  • Save mrdoob/919638 to your computer and use it in GitHub Desktop.
Save mrdoob/919638 to your computer and use it in GitHub Desktop.
Create 2 images (RGB and Grayscale) 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 )
im2.paste( im )
im2.save( file + "_color.jpg", "JPEG" )
im3 = Image.new( "L", im.size )
im3.paste( im.split()[ 3 ] )
im3.save( file + "_alpha.png", "PNG" )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment