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
Comment #1
robert castelo commentedHi,
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.
Comment #2
moonray commentedsubscribing
Comment #3
heimstein commentedjust in case, one has images in non-writable paths, this helps
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.
Comment #4
robert castelo commentedThanks 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.
Comment #5
robert castelo commentedComment #6
(not verified) commented