A number of the sites that we've been working with require large captions for image. A full example might be something like this:

Title of the Work
Artist Name
Acrylic on paper, mounted on linen. 9'3 1/4" x 10'3" (282.5 x 312.4 cm)

It would be great to be able to save these captions as the body of the image's node.

CommentFileSizeAuthor
#1 image_attach_captions.patch2.13 KBseanbfuller

Comments

seanbfuller’s picture

Status: Active » Needs review
StatusFileSize
new2.13 KB

Here's a first pass at bringing this feature in image_attach. Currently it is using the parent node's filter setting, which is probably wrong.

drewish’s picture

interesting... i think it'd be better to use the teaser though...

erwinova’s picture

The code not warking... may be the problem at line:

'$output .= '

-caption">'. check_markup($image->body, $node->format) .'

'."\n"; '

need help...

Hetta’s picture

Version: 6.x-1.x-dev » 5.x-2.x-dev
Status: Needs review » Needs work

From 2006, for 6.x, with "code needs review", and a "not working" in September.
Moved to 5.x-2.x, with "code needs work".

Hetta’s picture

marked http://drupal.org/node/228150 as duplicate

iantresman’s picture

I've made an Image module feature requested, and described a hack, that displays an image node's body text, as the image caption (but not in teasers), described here.

ericjam’s picture

Please implement this in a future update!!! Image Caption module requires you to add a caption class but doesn't allow you to specify WHICH size will receive the caption. Think improved automation for Image Attach.

joachim’s picture

Title: Image Attach captions » Use body text as Image Attach caption
Version: 5.x-2.x-dev » 6.x-1.x-dev

I'm not sure about this one.
It's a nice feature, but it's too much for many uses. So we need another setting, definitely.
I wonder whether it would be doable as another module with hook_form_alter -- but then there's the theming to consider.

At any rate, would need to be implemented for 6 first and then backported.

iantresman’s picture

I think many users would like to add a caption to their images, if the option were available. My hack mentioned above adds this feature, so it should be possible to put a kosher version of it into D6, together with an option to toggle the feature (which I couldn't figure out how to do).

ericjam’s picture

Title: Use body text as Image Attach caption » Caption option
Priority: Normal » Critical

iantresman your hack does not specify which node will receive the caption, i don't want captions in my teasers! just the full node view

iantresman’s picture

My hack displays the text from the image node, as a caption in only the full node.

You can see it in operation on this adult site, in the section "Prudery, superstition, and the Law (NSFW)", where you can see that none of the teaser images show a caption. But click on an entry with an image, to see that a caption appears beneath the image. Click the image, and a Lightbox2 pop-up appears (also containing the caption text, details). Click the link "View Image Details" to go to the image node, where the caption text is edited.

ericjam’s picture

Title: Caption option » Caption option - Hack Solved for Image Attach Title Caption
Priority: Critical » Normal
Status: Needs work » Closed (fixed)

Okay I hacked your hack and found the solution for my needs.

I just want to use the TITLE of the Node (Image) as the caption shown

Go to the bottom of your image_attach.module
function theme_image_attach_body($node) {

Put this right below image_display


    $output .= '<div style="width: '. ($info['width']-10) .'px" class="image-attach-caption">'. check_markup($image->title, $node->format) .'</div>'."\n";

Style in CSS as you like!

joachim’s picture

There is no need to hack the module to make changes to theme functions -- the whole point of the theme layer is that you can override these in your theme.

tdivito’s picture

Version: 6.x-1.x-dev » 6.x-1.0-beta6

In the 6.x-1.0-beta6 release (or maybe sometime before), there were some changes to some of the functions that broke a few of the other already published caption functions for image-attach. Here is the function I added in my template.php file. Hope it can help someone.

<?php

function theme_image_attach_attached_images($nid, $image_nodes = array(), $options = array()) {
  // Merge in defaults.
  $options += array(
    'size' => IMAGE_THUMBNAIL,
    'link' => 'image',
  );

  $img_size = $options['size'];
  $link_destination = $options['link'];

  // Link images to the attaching node.
  if ($link_destination == 'node') {
    $link_path = "node/$nid";
  }

  $output = '';
  foreach ($image_nodes as $image) {
    if (!node_access('view', $image)) {
      // If the image is restricted, don't show it as an attachment.
      continue;
    }

    // Link images to the image node.
    if ($link_destination == 'image') {
      $link_path = "node/$image->nid";
    }

    // Get a fresh copy of the attributes for each image node.
    $div_attributes = $options['attributes'];

    // Create CSS classes, beginning with those passed in to the function.
    $classes = array();
    if (isset($div_attributes['class'])) {
      $classes[] = $div_attributes['class'];
    }
    // replace with base class in DIV
    //$classes[] = 'image-attach-' . $teaser_or_body;
    $classes[] = 'image-attach-node-' . $image->nid;
    if (!$image->status) {
      $classes[] = 'image-unpublished';
    }
    $div_attributes['class'] = implode(' ', $classes);

    // Add the width as inline CSS.
    $info = image_get_info(file_create_path($image->images[$img_size]));
    if (!isset($div_attributes['style'])) {
      $div_attributes['style'] = '';
    }
    $div_attributes['style'] .= 'width: ' . $info['width'] . 'px;';

    $output .= '<div' . drupal_attributes($div_attributes) . '>';
    $image_img = image_display($image, $img_size);
    if ($link_path) {
      $output .= l($image_img, $link_path, array('html' => TRUE));
    }
    else {
      $output .= $image_img;
    }
	$caption = node_teaser($image->body);
	$output .= '<div class="caption">' . $caption . "</div>\n";
    $output .= "</div>\n";
	
  }

  return $output;
}
?>
joachim’s picture

You really shouldn't be using node_teaser() on every page view -- it's meant only to be used when you save a node. Retrieve the stored teaser from the $image node.