[Zope] PIL/Zope Problem

Jens Grewen zope@grewen.de
Fri, 27 Oct 2000 15:51:56 +0200


Hi ,
>
> I use this external Methode to generate thumbs from an image an write both
> in an mysql database.
> May this helps you
>
>
____________________________________________________________________________
> ____________
> from PIL.Image            import BICUBIC, BILINEAR, NEAREST
> from cStringIO            import StringIO
>
> import _mysql
> import MySQLdb
> import PIL
>
> def write(filename, pid):
>   db=MySQLdb.connect(db="shop",user="zope",passwd="")
>   c=db.cursor()
>   imgfile=open(filename,'rb')
>   sql_reset_img1="update PRODUCT set PIMAGE=NULL where PID="+ pid
>   sqlstr="update PRODUCT set PIMAGE='" +
> _mysql.escape_string(imgfile.read()) +"' where PID="+ pid
>   # do reset...
>   c.execute(sql_reset_img1)
>   # do the "update" load...
>   c.execute(sqlstr)
>   imgfile.close()
>   im = PIL.Image.open(filename)
>   fmt = im.format
>   if fmt == 'PNG':
>     fmt = 'JPEG'
>   size = (int('75'),int('75'))
>   x, y = im.size
>   if x > size[0]: y = y * size[0] / x; x = size[0]
>   if y > size[1]: x = x * size[1] / y; y = size[1]
>   size = x, y
>   im.draft(None, size)
>   im = im.resize(size)
>   im.size = size
>   im.save('/home/zope/tempimage/temp.jpg', fmt)
>   tempfile=open('/home/zope/tempimage/temp.jpg','rb')
>   sql_reset_img2="update PRODUCT set PTHUMB=NULL where PID="+ pid
>   sqlstri="update PRODUCT set PTHUMB='" +
> _mysql.escape_string(tempfile.read()) +"' where PID="+ pid
>   # do reset...
>   c.execute(sql_reset_img2)
>   # do the "update" load...
>   c.execute(sqlstri)
>   tempfile.close()
>   return 'image was written to db successfull'
>
____________________________________________________________________________


Jens


----- Original Message -----
From: "Marcello Lupo" <lupo@atisworld.com>
To: <zope@zope.org>
Cc: <andy.smith@iname.com>
Sent: Friday, October 27, 2000 2:38 PM
Subject: [Zope] PIL/Zope Problem


> Hi to all,
> i read all the documentation and made all things to let interact PIL and
> Zope and i cannot find the way to make it work.
> If i try to import PIL from pyton interpreter it works perfectly with:
>
> *******************************
> Python 1.5.2 (#1, Jul 17 1999, 22:10:16)  [GCC egcs-2.91.66
> 19990314/Linux (egcs- on linux2
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >>> import PIL
> >>>
data=PIL.Image.open("/home/httpd/listanozze/docs/images/prove/ccc.jpg","r")
> >>> print data.format
> JPEG
> >>> print data.info
> {'adobe_transform': 1, 'progression': 1, 'adobe': 100, 'jfif': 258}
> >>> print data.size
> (450, 309)
> >>>
> ******************************
>
> as you can see it works.
> But when i try to access PIL.Image.open from an external method in Zope
> i get:
>
> *******************************
>
>
>              Error Type: AttributeError
>              Error Value: Image
>
>
>
>              Troubleshooting Suggestions
>
>                   The URL may be incorrect.
>                   The parameters passed to this resource may be
> incorrect.
>                   A resource that this resource relies on may be
> encountering an error.
>
>              For more detailed information about the error, please refer
> to the HTML source for this page.
>
>              If the error persists please contact the site maintainer.
> Thank you for your patience.
>
>
> Traceback (innermost last):
>   File /home/httpd/Zope-2.1.6-src/lib/python/ZPublisher/Publish.py, line
> 214, in publish_module
>   File /home/httpd/Zope-2.1.6-src/lib/python/ZPublisher/Publish.py, line
> 179, in publish
>   File /home/httpd/Zope-2.1.6-src/lib/python/Zope/__init__.py, line 202,
> in zpublisher_exception_hook
>     (Object: ElementWithAttributes)
>   File /home/httpd/Zope-2.1.6-src/lib/python/ZPublisher/Publish.py, line
> 165, in publish
>   File /home/httpd/Zope-2.1.6-src/lib/python/ZPublisher/mapply.py, line
> 160, in mapply
>     (Object: pippo)
>   File /home/httpd/Zope-2.1.6-src/lib/python/ZPublisher/Publish.py, line
> 102, in call_object
>     (Object: pippo)
>   File /home/httpd/Zope-2.1.6-src/lib/python/OFS/DTMLMethod.py, line
> 150, in __call__
>     (Object: pippo)
>   File
> /home/httpd/Zope-2.1.6-src/lib/python/DocumentTemplate/DT_String.py,
> line 502, in __call__
>     (Object: pippo)
>   File
> /home/httpd/Zope-2.1.6-src/lib/python/DocumentTemplate/DT_Util.py, line
> 335, in eval
>     (Object: resize_image(foto))
>     (Info: foto)
>   File <string>, line 0, in ?
>   File
>
/home/httpd/Zope-2.1.6-src/lib/python/Products/ExternalMethod/ExternalMethod
.py,
> line 255, in __call__
>     (Object: resize_image)
>     (Info: ((<ZPublisher.HTTPRequest.FileUpload instance at 8565c90>,),
> {}, None))
>   File /home/httpd/Zope-2.1.6-src/Extensions/image_op.py, line 7, in
> resize_image
>     (Object: ElementWithAttributes)
> AttributeError: (see above)
>
> *********************************
>
> My external Method say:
> ****************************
> import PIL
>
> def resize_image(self, foto):
>
>         if foto:
>                 data=PIL.Image.open(foto)
>                 data=data.resize((128, 128))
>                 return data.size
>         else:
>                 return "Nothing"
>
> ***************************************
>
>
> Can anyone help me??
> Thanks
> Bye,
> MArcello
>
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )
>