Python Imaging Library (PIL) not working right in Maya Python (esp. saving textures)?

Hello, lately I’ve been trying to adapt my pipeline to PIL, which could be downloaded here:

http://www.pythonware.com/products/pil/

It’s a much cleaner and more efficient solution for texture manipulation such as cutting, pasting, extending, etc… on textures which we do a lot of. I’ve found convertSolidTx to be too clunky (slow, buggy and a memory hog, especially on really huge textures).

I’m running Maya 2009 and have dowloaded PIL version:
Python Imaging Library 1.1.6 for Python 2.5

Seeing that Maya 2009 is using Python 2.5.1, it would make sense that this version should work in theory. I load the libraries, and at first glance, it seems fine, e.g. in Maya Python Script Editor …

from PIL import Image
myImage = Image.open(“c:/temp/testSource.bmp”)
print myImage.format, myImage.size, myImage.mode
BMP (694, 1126) RGB

… so far so good, but when I do other simple things like first trying to show the image …

myImage.show()

Error: (0, ‘Error’)

Traceback (most recent call last):

File “<maya console>”, line 1, in <module>

File “C:\Python25\Lib\site-packages\PIL\Image.py”, line 1349, in show

_showxv(self, title, command)

File “C:\Python25\Lib\site-packages\PIL\Image.py”, line 1913, in _showxv

file = image._dump(format=format)

File “C:\Python25\Lib\site-packages\PIL\Image.py”, line 434, in _dump

self.save(file, format)

File “C:\Python25\Lib\site-packages\PIL\Image.py”, line 1305, in save

save_handler(self, fp, filename)

File “C:\Python25\Lib\site-packages\PIL\BmpImagePlugin.py”, line 236, in _save

ImageFile._save(im, fp, [(“raw”, (0,0)+im.size, 0, (rawmode, stride, -1))])

File “C:\Python25\Lib\site-packages\PIL\ImageFile.py”, line 489, in _save

s = e.encode_to_file(fh, bufsize)

IOError: (0, ‘Error’)

… and most importantly, trying to save it out …

myImage.save(“c:/temp/testDestination.bmp”)

Error: (0, ‘Error’)

Traceback (most recent call last):

File “<maya console>”, line 1, in <module>

File “C:\Python25\Lib\site-packages\PIL\Image.py”, line 1305, in save

save_handler(self, fp, filename)

File “C:\Python25\Lib\site-packages\PIL\BmpImagePlugin.py”, line 236, in _save

ImageFile._save(im, fp, [(“raw”, (0,0)+im.size, 0, (rawmode, stride, -1))])

File “C:\Python25\Lib\site-packages\PIL\ImageFile.py”, line 489, in _save

s = e.encode_to_file(fh, bufsize)

IOError: (0, ‘Error’)

… which first lead me to believe it’s a binary incompatibility between Maya’s Python (2.5.1) and PIL’s (2.5). However, when trying to do the exact same commands from standalone Python 2.5.4 (downloaded from python.org), it all works fine.

It’s kinda “half-working” in Maya it seems… does PIL completely work at all in Maya for anyone? If so, hope you wouldn’t mind lettin me in on the “secret sauce”. :):

Otherwise, I’m open to any other suggestions on libraries, classes, etc… anyone can point to for good, robust image-manipulation within Maya (even c++).

Thx for any feedback.

Are you possibly using 64bit version of Maya2009?
PIL, as far as I remember, only offered 32bit version for windows.
A lot of functions work in 64bit environment since majority of it’s implementation is done in python, but ones requires compiled code seems to not work at all.
I think we were able to use PIL under 32bit environment.

Maya’s API offers MImage class which is pretty handy in handling images.
I think that could be used instead of PIL.

That would definitely explain it, assuming that’s the case. PIL uses compiled extension modules, and those need to match the Python interpreter’s build configuration (x86 vs. x64, Release vs. Debug).

If you’re feeling adventurous, you could download the source and try compiling it for 64-bit. Although I would hit the PIL mailing list first, odds are someone’s gone down that road already, successful or not.

Thx for the input guys. But I’m definitely using Win32 for sure.

Oddly enough, it’s working when saving out png files, e.g.

from PIL import Image
myImage = Image.open(“c:/temp/testSource.bmp”)
print myImage.format, myImage.size, myImage.mode
myImage.save(“c:/temp/testDestination.png”)

Fails for bmp, tif, jpg, etc… though, e.g.

myImage.save(“c:/temp/testDestination.jpg”)
myImage.save(“c:/temp/testDestination.tif”)
myImage.save(“c:/temp/testDestination.bmp”)
myImage.save(“c:/temp/testDestination.tif”)
myImage.save(“c:/temp/testDestination.ppm”)

So it doesn’t sound like a binary incompatibility thing.

For now the ugly fugly workaround is to save things out in png, then convert in the end with Maya’s imgcvt command-line utility via system. Damn.

I think there’s some sort of incompatibility thing between Maya’s image-writing libraries and PIL’s …

if you are just converting image file from one format to other,
it could be as easy as:


import maya.OpenMaya as om
img = om.MImage()
img.readFromFile('C:/square.jpg')
img.writeToFile('C:/square.bmp','bmp')

i think it’s almost equivalent to imgcvt tool.

Hey YutaA, thx for the tip. That seems to work like a charm. Interesting how you can combine MayaAPI functions with Python. No need for system, sweet.

That’ll be a good hack for now. There may be a cleaner solution somewhere, I did notice functions in PIL docs like: Image.fromstring(mode, size, data, “raw”, raw mode, stride, orientation) which appear to be able to decode images into raw data. It might then be possible to feed this raw data into MImage via MImage::setPixels() or MImage::setFloatPixels() …

没有老瓦的终结者4终于上映拉.大家快用快播看啊!

Welcome to www.veryfreegames.comfree games download,free games,flash games,online games,games,games to play,arcade game,flash game,download gamesdownload free games,free game,online game,puzzle games,racing game,game,mahjong games,video games,psp games,downloadIn Mae QWest and the Sign of the Stars only you can help Mae read the stars and help her solve the mystery of her missing husband. Maes horoscope guides her through an epic journey after her husband is lost at sea. Do you have the sleuthing skills to uncover the truth and help her keep her family together? Several mini-games 3D rendered objects Heart warming story
[/list]

[b]电话录音系统[/b]主要功能:支持1–1280路电话同时录音;[b]录音电话机[/b]在录音系统本机上,实时监听任一路电话的通话;在录音系统本机上,根据主被叫号码、日期、时间、通道号等条件随时查询录音;网络查询电话录音和网络实时监听任意通道的通话;在录音系统本机和查询机器都有外网IP地址的广域网上,网络查询电话录音;[b]录音手表[/b]支持留言录音功能;(可选)根据权限删除、备份录音文件操作;根据用户权限实行分级管理;录音查询的回放、循环播放以及连续播放;[b]录音管理系统[/b]界面显示主被叫电话号码;自[b]电话录音设备[/b]动检测硬盘容量,录音文件可自动清理、转储;支持服务器端和客户端客户信息记录和自动弹出呼入客户的信息。具有交换机中继录音功能,可按分机查询录音。