Maybe u added some logo or something to your picture you display with lb2 and want users to be able to save it as such.

So, if u want to use imagecache image in "SAVE ORIGINAL" then add to template.php "theme_imagefield_image_imagecache_lightbox2" function u can find in lighbox2.formatter.inc and change line 187 from

$node_links[] = l($download_link_text, $item['filepath'], array('attributes' => array('target' => '_blank', 'id' => 'download_link_text')));

to

$node_links[] = l($download_link_text, imagecache_create_url($args['lightbox_preset'], $item['filepath']), array('attributes' => array('target' => '_blank', 'id' => 'download_link_text')));;

and u will have it like that. just wanted to share this with community.

Comments

stella’s picture

Maybe add a section on this to http://drupal.org/node/274487 along with a clearer explanation of how they can do this from within their own theme without modifying the lightbox2 code.

Cheers,
Stella

el_rob’s picture

I just stumbled over this post, as I was looking for this solution. Maybe I can clarify a bit...

I have a gallery page where the thumbnails are created by an imagecache preset named "small". Clicking on the thumbnail, lightbox opens the imagecache preset "big", which is basically the original picture, but with a copyright watermark added to it by imagecache_actions module. Now I do want visitors to be able to save the picture in the original size, but only the watermarked version. However by clicking on the link "Save original" in the lightbox, the original image is displayed.

By adding the following code to your template.php, the "Save original" link points to the imagecache preset opened by the lightbox, instead of the original picture:

/**
 * Function to set up the data needed for
 * theme_imagefield_image_imagecache_lightbox2().
 *
 * @param $field_name
 *   The field name the action is being performed on.
 * @param $item
 *   An array, keyed by column, of the data stored for this item in this field.
 * @param $formatter
 *   The formatter to use for the field.
 * @param $node
 *   The node object.
 * @param $view_preset
 *   The imagecache preset to be displayed on the node or in the view.
 * @param $lightbox_preset
 *   The imagecache preset to be displayed in the lightbox.
 * @return
 *   The themed imagefield + imagecache image and link.
 */
function phptemplate_imagefield_image_imagecache_lightbox2($view_preset, $field_name, $item, $node, $rel = 'lightbox', $args = array()) {
  if (!isset($args['lightbox_preset'])) {
    $args['lightbox_preset'] = 'original';
  }
  // Can't show current node page in a lightframe on the node page.
  // Switch instead to show it in a lightbox.
  if ($rel == 'lightframe' && arg(0) == 'node' && arg(1) == $node->nid) {
    $rel = 'lightbox';
  }
  $orig_rel = $rel;

  // Unserialize into original - if sourced by views.
  $item_data = $item['data'];
  if (is_string($item['data'])) {
    $item_data = unserialize($item['data']);
  }

  // Set up the title.
  $image_title = $item_data['description'];
  $image_title = (!empty($image_title) ? $image_title : $item_data['title']);
  $image_title = (!empty($image_title) ? $image_title : $item_data['alt']);

  $image_tag_title = '';
  if (!empty($item_data['title'])) {
    $image_tag_title = $item_data['title'];
  }

  if (variable_get('lightbox2_imagefield_use_node_title', FALSE)) {
    $node = node_load($node->nid);
    $image_title = $node->title;
  }

  // Enforce image alt.
  $image_tag_alt = '';
  if (!empty($item_data['alt'])) {
    $image_tag_alt = $item_data['alt'];
  }
  elseif (!empty($image_title)) {
    $image_tag_alt = $image_title;
  }

  // Set up the caption.
  $node_links = array();
  if (!empty($item['nid'])) {
    $attributes = array();
    $attributes['id'] = 'node_link_text';
    $target = variable_get('lightbox2_node_link_target', FALSE);
    if (!empty($target)) {
      $attributes['target'] = $target;
    }
    $node_link_text = variable_get('lightbox2_node_link_text', 'View Image Details');
    if (!empty($node_link_text)) {
      $node_links[] = l($node_link_text, 'node/'. $item['nid'], array('attributes' => $attributes));
    }
    $download_link_text = check_plain(variable_get('lightbox2_download_link_text', 'Download Original'));
    if (!empty($download_link_text) && user_access('download original image') && user_access('view imagefield uploads')) {
      $node_links[] = l($download_link_text, imagecache_create_url($args['lightbox_preset'], $item['filepath']), array('attributes' => array('target' => '_blank', 'id' => 'download_link_text')));
    }
  }

  $caption = $image_title;
  if (count($node_links)) {
    $caption .= '<br /><br />'. implode(" - ", $node_links);
  }
  if (isset($args['caption'])) {
    $caption = $args['caption']; // Override caption.
  }

  if ($orig_rel == 'lightframe') {
    $frame_width = variable_get('lightbox2_default_frame_width', 600);
    $frame_height = variable_get('lightbox2_default_frame_height', 400);
    $frame_size = 'width:'. $frame_width .'px; height:'. $frame_height .'px;';
    $rel = preg_replace('/\]$/', "|$frame_size]", $rel);
  }

  // Set up the rel attribute.
  $full_rel = '';
  $imagefield_grouping = variable_get('lightbox2_imagefield_group_node_id', 1);
  if ($imagefield_grouping == 1) {
    $full_rel = $rel .'['. $field_name .']['. $caption .']';
  }
  elseif ($imagefield_grouping == 2 && !empty($item['nid'])) {
    $full_rel = $rel .'['. $item['nid'] .']['. $caption .']';
  }
  elseif ($imagefield_grouping == 3 && !empty($item['nid'])) {
    $full_rel = $rel .'['. $field_name .'_'. $item['nid'] .']['. $caption .']';
  }
  elseif (isset($args['rel_grouping'])) {
    $full_rel = $rel .'['. $args['rel_grouping'] .']['. $caption .']';
  }
  else {
    $full_rel = $rel .'[]['. $caption .']';
  }
  $link_attributes = array(
    'rel' => $full_rel,
  );


  $attributes = array();
  if ($view_preset == 'original') {
    $image = theme('lightbox2_image', $item['filepath'], $image_tag_alt, $image_tag_title, $attributes);
  }
  else {
    $image = theme('imagecache', $view_preset, $item['filepath'], $image_tag_alt, $image_tag_title, $attributes);
  }

  if ($args['lightbox_preset'] == 'node') {
    $output = l($image, 'node/'. $node->nid .'/lightbox2', array('attributes' => $link_attributes, 'html' => TRUE));
  }
  elseif ($args['lightbox_preset'] == 'original') {
    $output = l($image, file_create_url($item['filepath']), array('attributes' => $link_attributes, 'html' => TRUE));
  }
  else {
    $output = l($image, imagecache_create_url($args['lightbox_preset'], $item['filepath']), array('attributes' => $link_attributes, 'html' => TRUE));
  }

  return $output;
}

Note, in the above code, we changed the following line:

$node_links[] = l($download_link_text, $item['filepath'], array('attributes' => array('target' => '_blank', 'id' => 'download_link_text'))); 

to point to the imagecache preset

$node_links[] = l($download_link_text, imagecache_create_url($args['lightbox_preset'], $item['filepath']), array('attributes' => array('target' => '_blank', 'id' => 'download_link_text')));

However, is there any chance to extend Lightbox2 modules core, to have the option of the "Save original" link pointing either to the original or an imagecache preset? That would be greatly appreciated!

Thanks,
Rob

stella’s picture

Category: task » feature
Status: Needs review » Active
dman’s picture

Code looks logical.
I also had need to remove access to the unwatermarked files. (Drupal experts could probably still get them if they tried ;=)
Yep, If there is to be a direct link to the file - it should be to the chosen file, not the system default.

terribly worded OP however!

mxt’s picture

How I can link to ANOTHER arbitrary imagecache preset, and not the already existing associated one?

Thank you for your help.

PS: + 1 for "However, is there any chance to extend Lightbox2 modules core, to have the option of the "Save original" link pointing either to the original or an imagecache preset? That would be greatly appreciated!"

mxt’s picture

Ok, I've got it: simply you have to indicate the imagecache preset you want to use, for example:

$imagecache_preset = '147x133'; // your imagecache preset name

$node_links[] = l($download_link_text, imagecache_create_url($imagecache_preset, $item['filepath']), array('attributes' => array('target' => '_blank', 'id' => 'lightbox2-download-link-text')));

Hope this help.