I posted this on BA but I'm posting it here as well.
I'm looking into manipulating images with Pillow in custom node trees. If I install Pillow and copy the PIL directory from
C:\Python34\Lib\site-packages
to
\bin\2.73\python\lib\site-packages
then I can import PIL just fine. I can save .png image files, but saving to any other image format type crashes Blender.
But if I run Python 3.4 in a command prompt, I can import PIL (the one from my C:\Python34 installation), and read, modify and save to any of the supported image formats.
The problematic code:
import bpy
import os
from extensions_framework import util as efutil
from PIL import Image, ImageEnhance, ImageFile
def realpath( path):
return os.path.realpath( efutil.filesystem_path( path))
brightness = 2.0
# Use an image loaded into Blender.
img = bpy.data.images['preview.jpg']
orig = Image.open( realpath( img.filepath))
ImageFile.MAXBLOCK = max( orig.size) ** 2
# Brighten the image.
enhancer = ImageEnhance.Brightness(orig)
bright = enhancer.enhance(brightness)
# Save the new image.
img_path = ( os.path.sep).join( realpath( img.filepath).split( os.path.sep)[:-1])
img_name = realpath( img.filepath).split( os.path.sep)[-1][:-4] # Remove '.jpg' from end
new_img = os.path.join( (os.path.sep).join( realpath( img.filepath).split( os.path.sep)))
# The following line crashes Blender.
# But if the string is changed to "_mod.png", it works.
bright.save( os.path.join( img_path, img_name + "_mod.jpg"))
What could the problem be? Why can't I do this from within Blender without it crashing?