Hi, I had a look at this module which provides a very common sense feature. One question though - why isn't it just implemented as a normal drupal filter? Why does it use js? That means it won't work for anyone that doesn't have js.

Just wondering because maybe it would be worth improving it to include an alternative option. Or coding a separate module.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

davidwhthomas’s picture

Yes, it could work too as an input filter.

I may include a input filter option as a sub-module, but feel free to submit a patch ;-)

regards,

DT

fletchgqc’s picture

Yeah I might give it a go if I have some time after the intensive project I'm on right now is finished. There are a few other things I'd like to add like using the title text as alt text if there is no alt text.

I've never parsed HTML with PHP. Do you know where I can look for help? Are there any handy functions to extract elements and attribute values from a HTML document?

davidwhthomas’s picture

I've already made an input filter that processes attached images and embeds them using imagecache and lightbox. It uses an [image] tag in the text and swaps it with a scaled image with lightbox popup and caption. You can see it on http://odt.co.nz

But... If the filter was going to caption embedded images, it may need to parse the html. This would be done using regular expressions which are kinda complicated but do the job perfectly too.

More info on regular expressions is here:

http://en.wikipedia.org/wiki/Regular_expressions

or:

http://php.net/preg_match

regards,

DT

fletchgqc’s picture

Attached is a module in its own right called "image_caption_filter".

It basically works like image_caption but it does the work by modifying the HTML code rather than using JS.

  • It will only operate on img tags with the class 'image-left', 'image-right' or 'standalone-image' and with a title attibute set.
  • If it finds a matching tag, it will place the img tag in a div with the width (using style="width:x") and class attributes set. A div tag of class "caption" is also added with the caption text obtained from the title. It removes the class attribute from the img tag. So, fairly similar to the js version.
  • An additional feature we put in because we needed it on our site: Only local images are allowed. tags missing alt attributes are also marked with huge pink warning text to draw attention to this fact.

Due to the static class names and the pink warning text it's not really ready for the prime-time. I think it needs configuration options for the class names of this form: if image has class [configurable], add class [configurable] to the containing div, remove class from image [yes/no].
Additionally: class applied to caption divs: [configurable].

If someone added that I think it could totally replace the js version. (?)

BTW how is your CVS access going? What needs to be sorted and when do you think this might happen?

davidwhthomas’s picture

Thanks v.much for this.

I will look at integrating it into image_caption.

I'm still waiting on a drupal admin to clean out my CVS D6 branches so I can start again.

At the moment, I can't submit any D6 patches :-(

But, it should be sorted in the near future.

regards,

DT

Anonymous’s picture

@fletchgqc: Good work. I prefer the filter instead of the module b/c no edit of the theme is required.

Now we need a smaller font for the caption text.

davidwhthomas’s picture

You don't need to edit the theme for the jQuery version.
As long as you can give the image a class of 'caption' it will work.
You can do that when entering the content also.

Anonymous’s picture

You're right. I've misread the documentation. Nevertheless, a filter would be a good choice.

fletchgqc’s picture

I found out that my filter makes your code not XHTML strict anymore. I'm going to remedy this. Do you want the patch? What is going on with this module anyway?

Surely it can't take that long to get CVS sorted out.

Should I use my code to start another module instead?

davidwhthomas’s picture

Hi there,

Yes, please submit the patch.

Apologies on the delay, I've been snowed under at work and this has been put on the back burner.

If you send it through I'll look at getting it added over this weekend.

regards,

DT

davidwhthomas’s picture

Version: » 6.x-2.2
Assigned: Unassigned » davidwhthomas
Status: Active » Closed (fixed)

commited to DRUPAL-6--2 branch.

http://drupal.org/node/298044

fletchgqc’s picture

Thanks David,

Attached is another version where I replaced the divs with spans.

The problem is that a div inside a p tag is invalid XHTML strict! So I changed them to span and personally I style them as display: block in my CSS. A bit ridiculous but it works and it's valid.

Sorry for uploading .tar.gzs instead of a patch... anyway I wouldn't necessarily commit this. It's just for info. I think we need to tackle this properly with some config options. I will look into this once internet is working at my home again!

davidwhthomas’s picture

Cool, thanks John,

I'll patch this update in shortly.

regards,

DT

mansspams’s picture

I wanted to suggest this filter to not use custom class names to identify images for caption magic if imagefield/CCK workflow is used but...

don't bother to help... imagefield/CCK approach inserts images in nodes below or above body field data on which input filters work, therefore image_caption_filter will not work on those images even in theory.

RichieRich’s picture

Hi there,

I can't get the image_caption_filter module to do anything at all. Just to be clear, am I right in thinking that all I have to do is add, for example, an 'image-left' class to the img for it to work?

Do I require both this module and the JQuery module to be enabled? I've tried both combinations but with no joy.

I've tried clearing the cache etc with no effect.

Here's an example where I've applied the 'standalone-image' class. It's the top image on this page:

http://www.ishigaki-japan.com/culture/haari

As you can see there's no caption (unless of course I've managed to fix it by the time you read this post).

Any help would be greatly appreciated.

Regards,

Rich

Geijutsuka’s picture

Yeah... I'm having the same problem- I must be missing something, but what?

bradweikel’s picture

For those having issues with the filter not working at all, check out #692374: Filter doesn't work on images with multiple classes and see if that's the problem. If not, try to pin down the specific problem and file a new issue.

vood002’s picture

Although #17 is still important to look at, be sure that you've also activated this filter for every input format you want to use it with on /admin/settings/filters/list first...I don't believe this is called out anywhere for image_caption_format.

NPC’s picture

I need to test this for my site, I really like the general idea of using a filter, but it may be too rigid (I don't want all of the existing images suddenly having pink captions, since there are hundreds of them). Subscribing.

NPC’s picture

It does work as needed, thank you very much! (especially with the patch to configure class to use and to handle multiple classes with images). This is a great module!

captnaimerica’s picture

I can't get the caption to align with the image when I float it left or right, I've read a lot of posts, but I was wondering what the best way to do it is? I went and applied this patch http://drupal.org/files/issues/image_caption.js_.patch but its still not working.

alberto facchini’s picture

Issue summary: View changes

I'm trying to use the Image caption module. All is working, but the caption has not enough space between the body text. How can I do to give more space? Can I write something in the CKeditor CSS or somewhere else?