دنبال کننده ها

۱۳۹۶ مهر ۹, یکشنبه

python - PIL Imaging Module putpalette issue

[ad_1]



so i'm trying to make a sprite generator for a game and i'm having an issue with applying the palette. The code is there so people can see how i done the code. It puts all the images together but doesn't get any of the palettes whatsoever. Anyone got any idea(s)?



# =============================================================== #
# Uses Python 2.7 with Pillow Imaging Library Module Version 4.2.1 #
# =============================================================== #
import glob
import os
import random
# Import Pillow (PIL) Image Module
from PIL import Image
# Add in array for multiple file saves for output
for N in range( 0, 16 ):

# Setup locations of image files
palette = [os.path.normpath( g ) for g in glob.glob( './images/palettes/*.png' )]
grips = [os.path.normpath( g ) for g in glob.glob( './images/grips/*.png' )]
pommels = [os.path.normpath( g ) for g in glob.glob( './images/pommels/*.png' )]
crossguards = [os.path.normpath( g ) for g in glob.glob( './images/crossguards/*.png' )]
blades = [os.path.normpath( g ) for g in glob.glob( './images/blades/*.png' )]

palette = Image.open( random.choice( palette ), 'r' )

# Add the parts
grip = Image.open( random.choice( grips ), 'r' )
pommel = Image.open( random.choice( pommels ), 'r' )
crossguard = Image.open( random.choice( crossguards ), 'r' )
blade = Image.open( random.choice( blades ), 'r' )

# Apply Palette
for image in (grip, pommel, blade, crossguard):
assert isinstance(palette.palette, object)
Image.putpalette(palette.palette)


composite = Image.new( 'RGBA', (32, 32) )

# Paste all parts together
composite.paste( grip )
composite.paste( pommel, (0, 0), pommel.convert() )
composite.paste( blade, (0, 0), blade.convert() )
composite.paste( crossguard, (0, 0), crossguard.convert() )

# Save the file(s) to output dir
composite.save( 'out.png' )



[ad_2]

لینک منبع