Use imagecache preset for large images

snelson - October 5, 2007 - 19:18
Project:jQuery Lightbox
Version:5.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

Maybe I'm missing something, but there doesn't seem to be a way to resize the large images. This would be useful when my client decides to upload a huge image.

I can code a patch if that helps, just not really sure where this should go. Maybe its more of a javascript thing, since it should be dependent on browser size.

#1

sun - October 5, 2007 - 21:35

Hm, that's certainly out of the scope of jLightbox. However, isn't there a field property for each Imagefield to assign a maximum width and height for all uploaded images of a field? I used that to ensure all images of jLightbox-enabled Imagefields do not exceed a certain size.

#2

snelson - October 6, 2007 - 23:47

Yeah, that's a solution. Do you think being able to set an imagecache preset for the lightboxed image would be a useful feature addition to this module, especially since we're integrating with imagecache in other places like imagefield display?

#3

sun - October 7, 2007 - 00:31

Currently, this would lead to great confusion and the CCK field settings UI would suffer from this. Let me explain:

In the field settings, you configure in which image size (imagecache preset) an Imagefield image should be displayed, separately for teaser and full view. What we want to alter is not the image size, but the link pointing to the image. Fortunately, Imagecache already provides all presets in two fashions: a pure image of a preset and the same 'as link'.

Imagine we have three presets: thumbnail, preview, original. Foreach of these presets, there are two options for each Imagefield and jLightbox is adding another one:

thumbnail
thumbnail as link
jLightbox thumbnail
preview
preview as link
jLightbox preview
original
original as link
jLightbox original

All we could currently do is to power all presets with different link sizes:

thumbnail
thumbnail as link
jLightbox (thumbnail)
jLightbox (preview)
jLightbox (original)
preview
preview as link
jLightbox (thumbnail)
jLightbox (preview)
jLightbox (original)
original
original as link
jLightbox (thumbnail)
jLightbox (preview)
jLightbox (original)

As you can see, the select boxes would be cluttered with many image display options. If you know a workaround, let me know.

#4

snelson - October 8, 2007 - 17:15

I was actually thinking more along the lines of a global preset for all full-size lightboxed images, since if someone wants to use it for one, the probably would want to use it for all. Something at /admin/settings/jlightbox - "Lightbox imagecache preset", unset by default.

#5

sun - October 8, 2007 - 17:43
Version:5.x-1.1» 5.x-1.x-dev

Sounds reasonable. Mind to create a patch? :)

#6

sime - February 11, 2008 - 21:17

Maybe look for a 'jlightbox' preset and use it if you find it.

<?php
/**
* Implementation of theme_imagefield_jlightbox().
*/
function theme_imagefield_jlightbox($namespace, $formatter, $field, $item, $attributes = array()) {
  ...
  ...
 
 
// Defer to a preset called jlightbox (if it exists) for the lightbox image.
 
if (count(imagecache_preset_by_name('jlightbox'))) {
   
$item['filepath'] = file_directory_path() .'/imagecache/jlightbox/'. $item['filepath'];
  }
 
$output = l($image, $item['filepath'], $link_attributes, NULL, NULL, FALSE, TRUE);

  return
$output;
}
?>

#7

sun - October 15, 2008 - 08:39

Hm. I was about to turn this code into a patch. But then I reconsidered - this would actually make all those additional (existing) ImageField presets/field formatters obsolete, wouldn't it?

#8

dgtlmoon - January 1, 2009 - 13:52

I just done a sneaky and hacked a theme hook...

extracts the filepath and passes it back thru imagecache

/**
* Implementation of theme_imagefield_jlightbox().
*/
function mytheme_imagefield_jlightbox($namespace, $formatter, $field, $item, $type, $attributes = array()) {
  $attributes['class'] = 'image '. $namespace;
  $gallery = '';

  $imagecache_path = file_create_url(file_directory_path() .'/imagecache/'. $namespace .'/'. $item['filepath']);
  $image = theme('imagecache', $namespace, $item['filepath'], $item['alt'], $item['title'], $attributes);

  if ($type == 'gallery') {
    $gallery = '['. form_clean_id($field['field_name']) .']';
  }
  $link_attributes = array(
    'rel' => 'lightbox'. $gallery,
    'title' => ($item['alt'] != $item['filename']) ? $item['alt'] : $item['title'],
  );


  preg_match('/(http.*?)"/', theme('imagecache', 'large_image', $item['filepath']), $matches);
  $output = l($image, $matches[1], $link_attributes, NULL, NULL, FALSE, TRUE);

  return $output;
}

 
 

Drupal is a registered trademark of Dries Buytaert.