[kupu-dev] question about enabling image captioning in Plone
Steve
lists at stevenkurzman.com
Tue Dec 5 19:38:50 CET 2006
Hello,
I have a related question about captions. I'm using kupu 1.4b2 and Plone
2.5.1 and the captioning for images in News Items works great except
for one thing.
It seems that, in lieu of hard coding the image's width, html2captioned.py
uses the width of the original image to set the width of the DIV tags for
captioning, which means it ignores the PIL scales. For example, I have an
336px wide image, which I've scaled as 'mini' or 200px wide. But the DIV
tags for the captioned image are set at 336px wide, which is quite a bit
wider than the 'mini' image.
I think I can see where this occurs in html2captioned.py (see code
below) but don't know enough python to fix this. Can anyone suggest how
to change the code so width is based on the scale of the image instead of
"width = target.getImage().getWidth()"?
Thanks,
Steve
if context and at_tool:
def replaceImage(match):
tag = match.group(1) or match.group(2)
attrs = ATTR_PATTERN.match(tag)
src = attrs.group('src')
klass = attrs.group('class')
width = attrs.group('width')
if src:
d = attrs.groupdict()
target = at_tool.reference_catalog.lookupObject(src)
if target:
# changed target.Description to target.Title in next line
# so caption is pulled from images' Title instead of Description
d['caption'] = newline_to_br(target.Title())
tag = CLASS_PATTERN.sub('', d['tag'])
tag = ALT_PATTERN.sub('', tag)
tag = END_TAG_PATTERN.sub('\\1 alt="%s"\\2' % escape(target.Title(),1), tag)
d['tag'] = tag
if not width:
width = target.getWidth()
if not width:
try:
width = target.getImage().getWidth()
except:
width = 150
d['width'] = width
return IMAGE_TEMPLATE % d
return match.group(0) # No change
On Mon, 11 Sep 2006 09:54:24 +0000, Duncan Booth wrote:
> "Jon Stahl" <jon at onenw.org> wrote:
>
>> [quoted text muted]
>
>> [quoted text muted]
> Ok, there were two bits of information missing from the instructions you
> followed, and a bug in the 1.3 drawers prevents the caption checkbox being
> displayed:
>
> First you need to have the 'link by uid' option turned on in the kupu
> config page. This is because the captioning needs to access the UID in
> order to find the image caption. The other thing is that the
> 'captioned_to_html' transform you create has to have input 'text/x-html-
> captioned', output 'text/html'.
>
> Then the Portal transform code sees two possible transforms from text/html
> to text/x-html-safe: the direct one using the safe_html transform, and the
> indirect route using html-to-captioned+captioned_to_html+safe_html. The
> policy forces it to use the indirect route.
>
> Finally in 1.3 the caption checkbox in the drawer is only displayed if the
> field output is x-html-captioned, so I customised kupu_wysiwyg_support.html
> to display it also for x-html-safe fields. If you upgrade to 1.4b1 (see
> plone.org/products/kupu) then the presence of the captioning checkbox may
> be controlled from the configlet (which also tells you if the transforms
> are configured correctly).
>
> In kupu_wysiwyg_support.html:
> usecaptions python:field and field.default_output_type=='text/x-html-
> captioned'
> becomes:
> usecaptions python:field and field.default_output_type in ('text/x-html-
> captioned','text/x-html-safe')
More information about the kupu-dev
mailing list