Hello Robert Castelo,

I would like to ask you, if you plan to continue your work on this module, or if you stoped it. In the second case, I could offer you to become a co-maintainer of this module to bring it out for version 5.

As it seems, there is no really simple solution for that, so there is a need for this module. For me, the code below works fine.

Here again is the short an simple code snippet. To finish this up, I would add an admin user-interface which let users set up the suffix (here ".teaser") and the resolution (here 100x100).

// $Id: teaser_images.module,v 2.0 2007/02/28 19:26:22 heimstein Exp $

function teaser_images_help($section) {
  switch ($section) {
    case 'admin/modules#description':
      return t('Converts images in teasers into thumbnails.');
    case 'node/add#teaser_images':
      return t('Converts images in teasers into thumbnails.');
    case 'admin/settings/teaser_images':
      return t('Converts images in teasers into thumbnails.');
  }
}

/**
 * Implementation of nodeapi().
 */
 function teaser_images_nodeapi(&$node, $op, $teaser, $page) {
  switch ($op) {
    case 'alter':
          $find = '/<img(.+?)>/i';
          $teaser = preg_replace_callback($find, "teaser_images_replace", $node->teaser);
    	  $node->teaser = "".$teaser;
    	break;
  }
}
 
function teaser_images_replace($image) {
  $image = $image[1];
  $find= '/src="(.+?)"/i';
  preg_match($find, $image, $matches);
  $image_regular = $matches[1];
  $parts = explode(".",$matches[1]);
  $parts[count($parts)-1] = 'teaser.'.$parts[count($parts)-1];
  $image_teaser = implode(".",$parts);
  
  $image_tag = ''
    .'<a target="_blank" href="'.$image_regular.'" >'
        .'<img src="'.($image_teaser).'" >'
    .'</a>'    
  ;
  if(!file_exists($_SERVER['DOCUMENT_ROOT'].$image_teaser)) {
    image_scale(
        $_SERVER['DOCUMENT_ROOT'].$image_regular, 
        $_SERVER['DOCUMENT_ROOT'].$image_teaser, 
        100, 100 
    );
  } 
  return $image_tag;
}

thanks.

Comments

robert castelo’s picture

Hi,
yes, would be good to bring this out for Drupal 5.

I'm tied up the rest of this week, but I'll look at your code next weekend and see how we can move this forward.

moonray’s picture

subscribing

heimstein’s picture

just in case, one has images in non-writable paths, this helps

// $Id: teaser_images.module,v 2.0.1 2007/03/10 00:00:00 heimstein Exp $

function teaser_images_help($section) {
  switch ($section) {
    case 'admin/modules#description':
      return t('Converts images in teasers into thumbnails.');
    case 'node/add#teaser_images':
      return t('Converts images in teasers into thumbnails.');
    case 'admin/settings/teaser_images':
      return t('Converts images in teasers into thumbnails.');
  }
}

/**
 * Implementation of nodeapi().
 */
 function teaser_images_nodeapi(&$node, $op, $teaser, $page) {
  switch ($op) {
    case 'alter':
          $find = '/<img(.+?)>/i';
          $teaser = preg_replace_callback($find, "teaser_images_replace", $node->teaser);
    	  $node->teaser = "".$teaser;
    	break;
  }
}
 
function teaser_images_replace($image) {
  $image = $image[1];
  $find= '/src="(.+?)"/i';
  preg_match($find, $image, $matches);
  $image_regular = $matches[1];
  $parts = explode(".",$matches[1]);
  $parts[count($parts)-1] = 'teaser.'.$parts[count($parts)-1];
  $image_teaser = implode(".",$parts);
  
  $image_tag = ''
    .'<a target="_blank" href="'.$image_regular.'" >'
        .'<img src="'.($image_teaser).'" >'
    .'</a>'    
  ;
  $hasTeaserImage = false;
  if(!file_exists($_SERVER['DOCUMENT_ROOT'].$image_teaser)) {
    $hasTeaserImage = image_scale(
        $_SERVER['DOCUMENT_ROOT'].$image_regular, 
        $_SERVER['DOCUMENT_ROOT'].$image_teaser, 
        100, 100 
    );
  } else {
    $hasTeaserImage = true;  
  }
  if($hasTeaserImage) {
      return $image_tag;
  } else {
      return $image;
  }        
}

otherwise the image will break with my earlier approach... but currently assuming that all non-writable imgs are propperly sized already (like icons, etc.)

further, it could be very very nice to integrate overlib ( http://www.bosrup.com/web/overlib/ ) to have full-res while hovering the img ;-)

i am still offering to support you with potential upgades on this module. just contact me in case.

all feedback on my code is appreciated.

regards,

uwe.

robert castelo’s picture

Version: master » 5.x-1.x-dev

Thanks for the code - I've made some adjustments and committed it as a Drupal 5 version.

Anyone who wants to try it make sure to read the README.txt file that comes with it.

robert castelo’s picture

Status: Active » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)