I've found a few scripts around the web for this but all of them seem far
more complicated than needed and don't fit into my image upload script.
Here is what I'm trying:
def optimizeImage(rawImage):
import os, uuid
from PIL import Image
postImage = Image.open(rawImage)
resImage = postImage.resize((800,600), Image.ANTIALIAS)
resImage.save(db.post.file, optimize=True, quality=70)
def new():
form=SQLFORM(db.post).process()
rawImage = db.post.file
if form.accepted:
optimizeImage(rawImage)
redirect(URL('static', 'content', args=form.vars.file))
return dict(form=form)
The ticket I get back says "<type 'exceptions.AttributeError'> 'Field'
object has no attribute 'read'"
File "/usr/local/lib/python2.7/site-packages/PIL/Image.py", line 1956, in open
prefix = fp.read(16)
AttributeError: 'Field' object has no attribute 'read'
What I'm trying to do here is take the uploaded image in /static/content,
resize and optimize it using PIL, then save over the original unoptimized
file.
I'm not at all good with Python yet but I thought this would work based on
some command line tests with PIL. What am I doing wrong? I want to keep
this as simple as possible.
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.