[Zope] How a method only returns the data of an image

Joel Burton joel@joelburton.com
Mon, 11 Mar 2002 10:01:42 -0500 (EST)


On Mon, 11 Mar 2002, Trevor Toenjes wrote:

> I need to make a method act like the clone of an image.
> Without extending the Image class...(I would like to do this in DTML or
> python-script)
> I am simply trying to get a method to return the exact data of an Image
> object, so it can be used in normal HTML <IMG
> src="myimage.jpg?somevariable">.  If the Image is a method, it can execute
> some logic based on the QUERY_STRING.
>
> example:  DTML_Method "myimage.jpg"
> # should look and smell like a JPG to the browser (but also execute some
> logic without
> # effecting the image header data)
> ----
> |  <dtml-call "RESPONSE.setHeader('Content-type', 'image/jpeg')">
> |  <dtml-var expr="therealimage.data">
> |  <dtml-var somelogic>
> ----
> But this doesn't return the proper data or Content-Length:
> "therealimage" is a standard Zope Image object.

One very easy solution is to have your script just redirect to the object.
<dtml-call "RESPONSE.redirect(...)">

Advantages:

* The user's browser can take advantage of their local cached copy, if
they have one, and any proxy servers can take advantage of their local
cached copy, if they have one, of the image. If there's a query as part of
the URL, many caching mechanisms won't show a cached version.

Disadavantages:

* User can see the real image URL (which might be a problem is your script
is meant to check credetials before presenting it)

* Two HTTP requests rather than one (but would still be faster in most
cases because of the caching)


Otherwise, you could get the image size with therealimage.get_size()
and put this in the header.

Anyone: is the a call to create the header for an image correctly by
itself? Looking briefly through Image.py, I didn't see it.

-- 

Joel BURTON  |  joel@joelburton.com  |  joelburton.com  |  aim: wjoelburton
Independent Knowledge Management Consultant