How a method only returns the data of an image
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. Any help is greatly appreciated... -Trevor
More info...setting the header works until I add additional methods. ---- | <dtml-call "RESPONSE.setHeader('Content-type', 'image/jpeg')"> | <dtml-var expr="therealimage.data"> ---- ...works ---- | <dtml-call "RESPONSE.setHeader('Content-type', 'image/jpeg')"> | <dtml-var expr="therealimage.data"> | | <dtml-var dosomething> ---- ...doesnt work properly. Returns the wrong Content-Length. -Trevor
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Trevor Toenjes Sent: Monday, March 11, 2002 7:50 AM To: zope@zope.org Subject: [Zope] How a method only returns the data of an image
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.
Any help is greatly appreciated... -Trevor
_______________________________________________ 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 )
do it in a Python script: ## Script (Python) "getImg" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters= ##title= ## req = container.REQUEST res = req.RESPONSE imgname=traverse_subpath[0] res.setHeader('Content-type', 'image/jpeg') therealimage=context[imgname] context.dosomething() return therealimage.data Tested, by creating a dummy dosomething. You basically need to use it like this: http://localhosy:8080/getImg/tick.gif where tick.gif is the image you want served, this gets put into the traverse_subpath as entry 0, which is then used to get the realimage. ps. This can be called from anywhere, it's just a url ;) hth Phil ----- Original Message ----- From: "Trevor Toenjes" <zope@toenjes.com> To: <zope@zope.org> Sent: Monday, March 11, 2002 2:31 PM Subject: [Zope] Using RESPONSE.setHeader to have a Method act like an Image
More info...setting the header works until I add additional methods. ---- | <dtml-call "RESPONSE.setHeader('Content-type', 'image/jpeg')"> | <dtml-var expr="therealimage.data"> ---- ...works
---- | <dtml-call "RESPONSE.setHeader('Content-type', 'image/jpeg')"> | <dtml-var expr="therealimage.data"> | | <dtml-var dosomething> ---- ...doesnt work properly. Returns the wrong Content-Length.
-Trevor
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Trevor Toenjes Sent: Monday, March 11, 2002 7:50 AM To: zope@zope.org Subject: [Zope] How a method only returns the data of an image
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.
Any help is greatly appreciated... -Trevor
_______________________________________________ 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 )
_______________________________________________ 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 )
AHH. Another clever workaround. I will play with this idea. This could be better than the "redirect solution", because it calls the image directly. AND I can see other uses for traverse_subpath[0], now that I see it in action. Thanks. -Trevor But I still have yet to find out if it is possible to manipulate the setHeader info in DTML/p-script. BTW, for the the thread- context.dosomething(contect, container.REQUEST) allows the DTML method to grab the QUERY_STRING, etc.
-----Original Message----- From: Phil Harris [mailto:phil@harris-family.info] Sent: Monday, March 11, 2002 9:56 AM To: Trevor Toenjes; zope@zope.org Subject: Re: [Zope] Using RESPONSE.setHeader to have a Method act like an Image
do it in a Python script:
## Script (Python) "getImg" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters= ##title= ## req = container.REQUEST res = req.RESPONSE
imgname=traverse_subpath[0] res.setHeader('Content-type', 'image/jpeg') therealimage=context[imgname] context.dosomething()
return therealimage.data
Tested, by creating a dummy dosomething.
You basically need to use it like this:
http://localhosy:8080/getImg/tick.gif
where tick.gif is the image you want served, this gets put into the traverse_subpath as entry 0, which is then used to get the realimage.
ps. This can be called from anywhere, it's just a url ;)
hth
Phil
----- Original Message ----- From: "Trevor Toenjes" <zope@toenjes.com> To: <zope@zope.org> Sent: Monday, March 11, 2002 2:31 PM Subject: [Zope] Using RESPONSE.setHeader to have a Method act like an Image
More info...setting the header works until I add additional methods. ---- | <dtml-call "RESPONSE.setHeader('Content-type', 'image/jpeg')"> | <dtml-var expr="therealimage.data"> ---- ...works
---- | <dtml-call "RESPONSE.setHeader('Content-type', 'image/jpeg')"> | <dtml-var expr="therealimage.data"> | | <dtml-var dosomething> ---- ...doesnt work properly. Returns the wrong Content-Length.
-Trevor
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Trevor Toenjes Sent: Monday, March 11, 2002 7:50 AM To: zope@zope.org Subject: [Zope] How a method only returns the data of an image
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.
Any help is greatly appreciated... -Trevor
_______________________________________________ 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 )
_______________________________________________ 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 )
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
Clever. :) I think this approach will work for now. It seems the easiest solution. Sometimes easier is better. The redirect does seem to slow down the response a little. I will revisit the whole setHeader manipulation at a later date. Thanks. -Trevor
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Joel Burton Sent: Monday, March 11, 2002 10:02 AM To: Trevor Toenjes Cc: zope@zope.org Subject: Re: [Zope] How a method only returns the data of an image
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
_______________________________________________ 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 )
participants (3)
-
Joel Burton -
Phil Harris -
Trevor Toenjes