[Zope-Annce] ImageTag_CorePatch v.0.3

Marc Lindahl marc at bowery.com
Sun Jan 25 12:57:39 EST 2004


Available (once published) here: 
http://zope.org/Members/bowerymarc/ImageTag_CorePatch/0.3

Changes since last release:
	* Version 0.3
	* added ANTIALIAS to thumbnail generation (needs PIL 1.1.3 or later)
	* convert image to RGBA (previously RGB) before thumbnail (preserve 
transparency)
	* based tag() code on Image version 1.148, with additional fields from 
Plones's imagePatch.py (args are tag(height, width, alt, scale, xscale, 
yscale, css_class, title, longdesc), and if border is not specified, 
then it's set to 0.  Remove any other empty/unused attributes.
	* added method Image.pil_tag() with the exact same syntax as tag(), in 
case tag is further overridden (as Plone does, evidently)
	

README:

HotPatch Image.tag  to use PIL to size images (useful for thumbnails).
Also fixes so-called intelligent scaling to actually be intelligent.

Here's an example of using the new thumb method directly:

	 <img src=""
	 tal:on-error="structure string:<img src='${img/absolute_url}' 
alt='${here/title}' align=${alignment} hspace=${hs} vspace=${vs} 
border=${brd}) />"
	tal:attributes="src 
string:${img/absolute_url}/thumb?width=100&imtype=PNG;
					align alignment;
					hspace hs;
					vspace vs;
					border brd"/>

What that does is try to use thumb, and if it doesn't work fall back to 
rendering the image normally.  It also shows usage of some of the 
extended properties.  Since only width is specified the image will be 
proportionally resized (same applies for height only), and the imtype 
converts it to PING (check PIL docs, but the most useful types are 
JPEG, GIF, PNG), which preserves any transparency (alpha) the image 
might have.


Here's an example of using tag with PIL resizing:

<span tal:replace="structure python:img.tag(width=200) />

or

<span tal:replace="structure python:img.pil_tag(width=200) />

Note that this patch adds 'pil_tag' which you can test for if you're 
not sure tag() has been re-patched (evidently Plone does this)




More information about the Zope-Announce mailing list