Hey there - i find it strange that i could not find any approaches to my following problem:

I run an actual set of Drupal6, CCK, Imagefield, Imagecache (unluckily without .htaccess/cleanurls and therefore useless) and i want to use Imagefields:

1 - to show a cropped part of an image (188px/116px) in teaser AND full node (i not only want define the cropping points manually, but also to desaturate the image, so i chose to take care of this in photoshop)

2 - to appear in a node's teaser to click-direct the user onto the full node

3 - to appear in the full node in the same cropped form as in the teaser, but now to link onto a separate imagefield, which shows the other, full image.

4 - ideally to be combined with lightbox2 or thickbox (using 2 different fields), but this is optional.

... how would you approach to this problem? i am currently unaware of how to link those two fields. i am pretty sure it could be done in contemplate, but how would you do that exactly?

The best documented solution - to combine an imagecache "crop and scale" preset with the imagefield is no option because i want to have control over the cropping's positions/dimensions.

Comments

zach harkey’s picture

I would create two image fields for this content type:

1. field_image (this is your full image)

2. field_image_teaser (this is your custom teaser image)

Let's assume your content type is called 'foo',

If, for example, the name of your content type was 'foo', create a file named node-foo.tpl.php in your theme directory. In it, you could put something like this:


<?php
// Format the teaser image
// This should technically be done in theme_node_preprocess().
if ($field_image_teaser) {
  // Replace 'small' with the name of your imagecache preset.
  $image_teaser = theme('imagecache', 'small', $field_image_teaser[0]['filepath'], $node->title, $node->title);
}
?>

<div class="node">

  <?php // Teaser view
    if ($teaser): ?>

    <?php // Print the teaser image as a link to the full node.
      print l($image_teaser, 'node/'. $nid, array('html' => 'TRUE')) ?>

      <!-- Other content here -->

  <?php // Full view
    else: ?>

    <?php // Print the teaser image again, but this time link it to the full image using thickbox.
      print l($image_teaser, $field_image[0]['filepath'], array('html' => 'TRUE', 'attributes' => array('class' => 'thickbox'))) ?>
    
      <!-- Other content here -->

  <?php endif ?>

</div>

Of course my example is extremely bare bones. Your template will surely output the title and other fields. You will probably also want to provide some defaults in case the fields are empty.

mimhakkuh’s picture

Fantastic - thx Zach Harkey;

I used your example the following way:

<?php
// Format the teaser image
// This should technically be done in theme_node_preprocess().
if ($field_image_standard_thumb) {
  // Replace 'small' with the name of your imagecache preset.
  $image_standard_thumb = theme('imagecache', 'desaturate_-_resize_182px-110px', $field_image_standard_thumb[0]['filepath'], $node->title, $node->title);
}
?>

<div class="node">

  <?php // Teaser view
    if ($teaser): ?>

    <?php // Print the teaser image as a link to the full node.
      print l($image_standard_thumb, 'node/'. $nid, array('html' => 'TRUE')) ?>

      <!-- Other content here -->

  <?php // Full view
    else: ?>

    <?php // Print the teaser image again, but this time link it to the full image using thickbox.
      print l($image_standard_thumb, $field_image_standard_full[0]['filepath'], array('html' => 'TRUE', 'attributes' => array('rel' => 'lightbox2'))) ?>
   
      <!-- Other content here -->

  <?php endif ?>

</div>

... the only thing missing is the implementation of an Imagecache preset for the fullsize image. It is still calling for the original fullsize, though, i prepares a *max-500px* preset to be used within the lightbox2 presentation.

quicksketch’s picture

You need to link to the ImageCache version, not the full size version.

    $preset_filepath = imagecache_create_url('whatever_your_imagecache_preset_name', $field_image_standard_full[0]['filepath']);
    print l($image_standard_thumb, $preset_filepath, array('html' => 'TRUE', 'attributes' => array('rel' => 'lightbox2')))
quicksketch’s picture

Status: Active » Fixed

Marking fixed, please reopen if you have further questions on this topic.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

mimhakkuh’s picture

Status: Closed (fixed) » Postponed (maintainer needs more info)

Just re-opened this topic. I got stuck with the mentioned technique trying to prevent empty imagefields to be printed. I guess this is a matter of inserting the correct php to stop my template behaving like this.

I've put a detailed explanation on the matter in Zen's support request queue:
http://drupal.org/node/450862

Currently I am using the versions:

Drupal 6.10
Content Construction Kit (CCK) 6.x-2.2
FileField 6.x-3.0
ImageField 6.x-3.0
ImageCache 6.x-2.0-beta9
Lightbox2 6.x-1.9

Zen sub-theme based on 6.x-1.0

Your help is appreciated!

quicksketch’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

Support for custom theming is generally not provided in the ImageField queue, though it doesn't seem that your request is really related to this issue at all. Closing after lack of activity.