diff --git a/pyweb/mumble/MumbleCtlDbus.py b/pyweb/mumble/MumbleCtlDbus.py index 5684d36..073066c 100644 --- a/pyweb/mumble/MumbleCtlDbus.py +++ b/pyweb/mumble/MumbleCtlDbus.py @@ -261,7 +261,7 @@ class MumbleCtlDbus_118(MumbleCtlBase): def setTexture(self, srvid, mumbleid, infile): # open image, convert to RGBA, and resize to 600x60 - img = Image.open( infile ).convert( "RGBA" ).transform( ( 600, 60 ), Image.EXTENT, ( 0, 0, 600, 60 ) ); + img = infile.convert( "RGBA" ).transform( ( 600, 60 ), Image.EXTENT, ( 0, 0, 600, 60 ) ); # iterate over the list and pack everything into a string bgrastring = ""; for ent in list( img.getdata() ): diff --git a/pyweb/mumble/MumbleCtlIce.py b/pyweb/mumble/MumbleCtlIce.py index 6da5339..7408310 100644 --- a/pyweb/mumble/MumbleCtlIce.py +++ b/pyweb/mumble/MumbleCtlIce.py @@ -15,6 +15,7 @@ * GNU General Public License for more details. """ +from StringIO import StringIO from os.path import exists, join from os import unlink, name as os_name from PIL import Image @@ -372,7 +373,7 @@ class MumbleCtlIce_118(MumbleCtlBase): @protectDjangoErrPage def setTexture(self, srvid, mumbleid, infile): # open image, convert to RGBA, and resize to 600x60 - img = Image.open( infile ).convert( "RGBA" ).transform( ( 600, 60 ), Image.EXTENT, ( 0, 0, 600, 60 ) ); + img = infile.convert( "RGBA" ).transform( ( 600, 60 ), Image.EXTENT, ( 0, 0, 600, 60 ) ); # iterate over the list and pack everything into a string bgrastring = ""; for ent in list( img.getdata() ): @@ -522,8 +523,10 @@ class MumbleCtlIce_122(MumbleCtlIce_120): @protectDjangoErrPage def setTexture(self, srvid, mumbleid, infile): - img = open( infile, "rb" ) - self._getIceServerObject(srvid).setTexture(mumbleid, img) + buf = StringIO() + infile.save( buf, "PNG" ) + buf.seek(0) + self._getIceServerObject(srvid).setTexture(mumbleid, buf.read()) class MumbleCtlIce_123(MumbleCtlIce_120): @@ -534,7 +537,7 @@ class MumbleCtlIce_123(MumbleCtlIce_120): @protectDjangoErrPage def getTexture(self, srvid, mumbleid): - texture = self.getRawTexture(srvid, mumbleid); + texture = self.getRawTexture(srvid, mumbleid) if len(texture) == 0: raise ValueError( "No Texture has been set." ); from StringIO import StringIO @@ -542,8 +545,9 @@ class MumbleCtlIce_123(MumbleCtlIce_120): @protectDjangoErrPage def setTexture(self, srvid, mumbleid, infile): - # open image, convert to RGBA, and resize to 600x60 - img = open( infile, "rb" ) - self._getIceServerObject(srvid).setTexture(mumbleid, img) + buf = StringIO() + infile.save( buf, "PNG" ) + buf.seek(0) + self._getIceServerObject(srvid).setTexture(mumbleid, buf.read()) diff --git a/pyweb/mumble/models.py b/pyweb/mumble/models.py index 2d4109e..42577c9 100644 --- a/pyweb/mumble/models.py +++ b/pyweb/mumble/models.py @@ -592,12 +592,12 @@ class MumbleUser( models.Model ): """ Get the user texture as a PIL Image. """ return self.server.ctl.getTexture(self.server.srvid, self.mumbleid); - def setTexture( self, infile ): - """ Read an image from the infile and install it as the user's texture. """ - self.server.ctl.setTexture(self.server.srvid, self.mumbleid, infile) + def setTexture( self, image ): + """ Install the given image as the user's texture. """ + self.server.ctl.setTexture(self.server.srvid, self.mumbleid, image) texture = property( getTexture, setTexture, - doc="Get the texture as a PIL Image or read from a file (pass the path)." + doc="Get the texture as a PIL Image or set the Image as the texture." ); def hasTexture( self ): diff --git a/pyweb/mumble/views.py b/pyweb/mumble/views.py index c0b6160..fe525af 100644 --- a/pyweb/mumble/views.py +++ b/pyweb/mumble/views.py @@ -16,6 +16,7 @@ import simplejson from StringIO import StringIO +from PIL import Image from django.shortcuts import render_to_response, get_object_or_404, get_list_or_404 from django.template import RequestContext @@ -156,7 +157,7 @@ def show( request, server ): if request.method == 'POST' and 'mode' in request.POST and request.POST['mode'] == 'texture' and registered: textureform = MumbleTextureForm( request.POST, request.FILES ); if textureform.is_valid(): - user.setTexture( request.FILES['texturefile'] ); + user.setTexture( Image.open( request.FILES['texturefile'] ) ); return HttpResponseRedirect( reverse( show, kwargs={ 'server': int(server), } ) ); else: textureform = MumbleTextureForm();