So I changed it to this:
def makeThumbnail(dbtable,ImageID,size=(200,200)):
try:
thisImage=db(dbtable.id==ImageID).select()[0]
import os, uuid
except:
print "Error while loading libraries"
return
try:
from PIL import Image
except:
print "Error while Importing PIL library"
return
print request <http://127.0.0.1:8000/examples/global/vars/request>.folder +
'uploads/' + thisImage.Image
im=Image.open(request
<http://127.0.0.1:8000/examples/global/vars/request>.folder + 'uploads/' +
thisImage.Image)
im.thumbnail(size,Image.ANTIALIAS)
"""thumbName='uploads.thumb.%s.jpg' % (uuid.uuid4())
im.save(request.folder + 'uploads/' + thumbName,'jpeg')
thisImage.update_record(thumb=thumbName)"""
thisImage.update_record(thumb=db.Images.thumb.store(im,
filename='thumbnail.jpg'))
response <http://127.0.0.1:8000/examples/global/vars/response>.flash =
'Thumb created everything went fine'
return
Now I get an error message which I don't understand:
Traceback (most recent call last):
File "F:\Website\web2py\gluon\restricted.py", line 209, in restricted
exec ccode in environment
File "F:/Website/web2py/applications/testthumb/controllers/default.py"
<http://127.0.0.1:8000/admin/default/edit/testthumb/controllers/default.py>,
line 128, in <module>
File "F:\Website\web2py\gluon\globals.py", line 185, in <lambda>
self._caller = lambda f: f()
File "F:/Website/web2py/applications/testthumb/controllers/default.py"
<http://127.0.0.1:8000/admin/default/edit/testthumb/controllers/default.py>,
line 121, in newImage
makeThumbnail(dbtable,form.vars.id,(200,200))
File "F:/Website/web2py/applications/testthumb/controllers/default.py"
<http://127.0.0.1:8000/admin/default/edit/testthumb/controllers/default.py>,
line 106, in makeThumbnail
thisImage.update_record(thumb=db.Images.thumb.store(im,
filename='thumbnail.jpg'))
File "F:\Website\web2py\gluon\dal.py", line 8442, in store
shutil.copyfileobj(file, dest_file)
File "C:\Python27\lib\shutil.py", line 48, in copyfileobj
buf = fsrc.read(length)
File "C:\Python27\lib\site-packages\PIL\Image.py", line 512, in __getattr__
raise AttributeError(name)
AttributeError: read
On Thursday, September 6, 2012 10:42:16 PM UTC+2, Anthony wrote:
>
> On Thursday, September 6, 2012 4:23:50 PM UTC-4, BlueShadow wrote:
>>
>> the link directs to this group Anthony.
>>
>
> Yes, I know, but I noticed you're code didn't implement that solution so
> was wondering if you had tried it.
>
>
>> I didn't try:
>> thisImage.update_record(thumb=db.Images.thumb.store(im, filename=
>> 'thumbnail.jpg'))
>> this would store the thumb directly in the database?
>>
>
> No, it will rename and store the file on the filesystem (assuming that's
> how the "thumb" field is defined) and store the new name in the "thumb"
> field, just as if you did an upload with SQLFORM.
>
> Anthony
>
--