You are not logged in.

#1 2013-01-13 11:34:48

replabrobin
Member
Registered: 2010-05-06
Posts: 159

python2-imaging 1.1.7-7 issue

I'm running x_64 arch up to date. I wanted to test a program that runs on our ubuntu servers and also win32 etc etc. From the following script I seem to see that the pacman version of PIL is giving different results from elsewhere

import os
import Image

_7x7cdef=[(0, 0, 2), (0, 1, 2), (0, 2, 2), (0, 3, 2), (0, 4, 2),
		(0, 5, 2), (0, 6, 0), (1, 0, 2), (1, 1, 2), (1, 2, 2),
		(1, 3, 2), (1, 4, 0), (1, 5, 0), (1, 6, 0), (2, 0, 2),
		(2, 1, 2), (2, 2, 2), (2, 3, 0), (2, 4, 0), (2, 5, 0),
		(2, 6, 0), (3, 0, 2), (3, 1, 2), (3, 2, 0), (3, 3, 0),
		(3, 4, 0), (3, 5, 1), (3, 6, 1), (4, 0, 2), (4, 1, 0),
		(4, 2, 0), (4, 3, 0), (4, 4, 1), (4, 5, 1), (4, 6, 1),
		(5, 0, 2), (5, 1, 0), (5, 2, 0), (5, 3, 1), (5, 4, 1),
		(5, 5, 1), (5, 6, 1), (6, 0, 0), (6, 1, 0), (6, 2, 0),
		(6, 3, 1), (6, 4, 1), (6, 5, 1), (6, 6, 1)]
def save_corner(fnRoot,fg=(255,255,255),bfg=(229,229,229),cn='tl'):
	dn = os.path.dirname(fnRoot)
	if not dn: dn = os.getcwd()
	fn = os.path.join(dn,'%02x%02x%02x%02x%02x%02x_%s.gif' % (fg+bfg+(cn,)))
	if os.path.isfile(fn): return
	bg = (fg[0]!=255 and 255 or 254,255,255)
	im = Image.new('RGB',(7,7),bg)
	C = {2:bg,0:bfg,1:fg}
	for i,j,c in _7x7cdef:
		if cn=='tr':
			i = 6-i
		elif cn=='bl':
			j = 6-j
		elif cn=='br':
			i = 6-i
			j = 6-j
		elif cn!='tl':
			raise ValueError('Unknown corner name %r'%cn)
		im.putpixel((i,j),C[c])
	im.save(fn.replace('.gif','-orig.gif'))
	imo = im.convert('P',dither=Image.NONE,palette=Image.ADAPTIVE,colors=3)
	palette = imo.getpalette()
	transparency = None
	for i in xrange(0,3*3,3):
		print i,tuple(palette[i:i+3]),bg
		if tuple(palette[i:i+3])==bg:
			transparency = i / 3
			break
	imo.save(fn,transparency=transparency)

if __name__=='__main__':
	save_corner('output/xxx')

when I run the above with the builtin python2(python2 2.7.3-4) I see the following

robin@bunyip ~/code/tpil/charts:
$ python2 tpil.py
0 (0, 0, 0) (254, 255, 255)
3 (0, 0, 0) (254, 255, 255)
6 (0, 0, 0) (254, 255, 255)
Traceback (most recent call last):
  File "tpil.py", line 45, in <module>
    save_corner('output/xxx')
  File "tpil.py", line 42, in save_corner
    imo.save(fn,transparency=transparency)
  File "/usr/lib/python2.7/site-packages/PIL/Image.py", line 1439, in save
    save_handler(self, fp, filename)
  File "/usr/lib/python2.7/site-packages/PIL/GifImagePlugin.py", line 281, in _save
    + chr(0))
TypeError: int() argument must be a string or a number, not 'NoneType'

on the other platforms we typically build our own python environment so I tried that on my arch system using the standard configure make dance for python (python2 2.7.3-4) & PIL (Imaging-1.1.7.tar.gz) with --prefix=$HOME/LOCAL. When I run this self built python27 I see the following

$ python27 tpil.py
0 (255, 255, 255) (254, 255, 255)
3 (254, 255, 255) (254, 255, 255)

it seems the self built python2.7.3+pil 1.1.7 is behaving as I expect (ie we do detect the transparent colour index in the PALETTE image imo). From the output images & the print statements I deduce that the difference/failure is in the  statement

[bold]imo = im.convert('P',dither=Image.NONE,palette=Image.ADAPTIVE,colors=3)[/bold]

so what am I doing wrong? Or is this an issue with the distributed python2-imaging?

Incidentally the above code is used to generate some image corners for dynamically generated html content.

Offline

Board footer

Powered by FluxBB