Re-resizing node images

tic2000 - March 22, 2007 - 11:24
Project:Node Images
Version:5.x-1.x-dev
Component:Miscellaneous
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

I've made some modifications to the node_images module so that it allows the upload of 2 size images apart the full picture. I've also added the code so that if you want to resize the node images you can do that and you're not forced to re-upload all the images.
The re-resizing part I tried to make it as a tab in the settings page but i couldn't (if anyone can do it feel free to do it) so it's in the admin/build part of the administrations (after all it has something to do with buildin the content of the site).
If anyone is interested in this let me know

#1

janosch - March 23, 2007 - 21:08

That sounds very great, i would definately need this. Maybe as well an option to delete the original and keep the 2 resized? That way users can upload large pictures without being annoyed by a limit notice, and it wouldn't take as much space up either.

#2

tic2000 - March 25, 2007 - 13:00

I don't have a cvs account (or at least is this I think it's called) and I don't know and don't have the time to learn how to create a patch file. I can try to upload my new module file. If anyone can create a patch from it, feel free to do so. For the new file to work, you need to alter the node_images table inserting 2 new columns (mediumpath varchar(255) NOT NULL default '' and mediumsize int(10) unsigned NOT NULL default '0')
If anyone interested my function to display images is:

<?php
/**
* Show node images in the node view.
*/
function [template_name]_node_images_view($node, $teaser, $page, $format = NULL) {
  if (
arg(2) == 'image_gallery' || empty($node->node_images)) return;

 
$output = '';
 
$i = 0;

 
// set maximum number of images for teaser/body
 
$view = ($teaser ? 'teaser' : 'body');
 
$count = variable_get('node_images_'.$view.'_images_'.$node->type, 2);
  if (isset(
$count) && $count === 0) return;
  if (!
$format) {
   
$format = variable_get('node_images_'.$view.'_format_'.$node->type, 'thumbs');
  }

  foreach((array)
$node->node_images as $id=>$image) {
   
$description = check_plain($image->description);
   
$pattern = '<img src="%path" alt="%description" class="%class" />';
   
$thumb = strtr($pattern, array('%path'=>file_create_url($image->thumbpath), '%description'=>$description, '%class' => 'node_image_tn'));
   
$medium = strtr($pattern, array('%path'=>file_create_url($image->mediumpath), '%description'=>$description, '%class' => 'node_image_md'));
   
$fullsize = strtr($pattern, array('%path'=>file_create_url($image->filepath), '%description'=>$description, '%class' => 'node_image'));

    if (
$info = getimagesize($image->filepath)) {
     
$width = $info[0] + 36;
     
$height = $info[1] + 36;
    }
    else {
     
$width = 420;
     
$height = 315;
    }

    if (
$format == 'thumbs') {
     
$output .= '<a href="'.url('node/'.$node->nid).'" title="'.$description.'">'.$thumb.'</a> ';
    }
    elseif (
$format == 'medium') {
     
$output .= '<a href="javascript:void(0);" title="'.$description.'" onclick="window.open(\''.
       
file_create_url($image->filepath).'\', \'\', \'height='.$height.',width='.$width.'\');">'.$medium.'</a> ';
    }
    else {
     
$output .= $fullsize . ' ';
    }
    if (
$count>0 && ++$i >= $count) break;
  }
  return
$output;
}
?>

I use a class for node images cause I want my pages to be XHTML 1.0 strict, and setting the width and height of images in img tag brakes the strictness.

AttachmentSize
node_images_4.patch 35.96 KB

#3

tic2000 - March 25, 2007 - 13:09

A note anyway, even if an option to delete the original image is set, the warning will still remain, cause the image is uploaded before any resizing and copying. As a consequence the image still has to respect the server limits.

#4

tic2000 - April 21, 2007 - 18:38
Category:task» feature request

OK, I have done a proper patch to create an admin page for resizing the thumbnails after they are uploaded. To resize you go first to admin/settings/node_images and enter the size you want, after that you go to admin/build/node_images, check the box and hit enter. That's all.
Maybe I'll come with the path to enable the thickbox gallery for node images when I'll have the time.

AttachmentSize
node_images_5.patch 2.81 KB

#5

Summit - September 5, 2008 - 12:55

Hi,
Will this patch be committed? Looking for resizing option.

greetings,
Martijn

#6

ahoria - October 7, 2008 - 19:06

A D6 port maybe?

 
 

Drupal is a registered trademark of Dries Buytaert.