When you use an image that is smaller or equal to the thumbnail size in the settings page the thumbnail isn't generated, yet the module tries to reference it with the img tags.

When the image is smaller you can either reference the original image or create a thumbnail by copying the original image.

CommentFileSizeAuthor
#7 node_images_7.patch9.61 KBstefano73

Comments

oriol_e9g’s picture

Same problem!

When the image is smaller or equal than the thumbnails Resolution the thumbnail is no generated!

oriol_e9g’s picture

I have fix this problem adding this patch: http://drupal.org/node/147538

nevets’s picture

Another appoach to handling images smaller than the thumbnail size is to add logic in _node_images_create_thumbnail() that makes sure the thumbnail was generated and if not uses the original image as the thumbnail. Here is my modified version of the function (sorry no patch)

function _node_images_create_thumbnail($path, $suffix='_tn') {
  $size = variable_get('node_images_thumb_resolution', '100x100');
  list($width, $height) = explode('x', $size);
  $dest_path = preg_replace('!(\.[^/.]+?)?$!', "$suffix\\1", $path, 1);
    
  if ($size = getimagesize($path)) {
   if ( image_scale($path, $dest_path, $width, $height) ) {
	   $info = image_get_info($dest_path);
	   $thumb = new stdClass();
	   $thumb->filename = basename($dest_path);
	   $thumb->filepath = $dest_path;
	   $thumb->filesize = $info['file_size'];
	   $thumb->filemime = $info['mime_type'];
	   return $thumb;
   }
   else {
	   $thumb = new stdClass();
	   $thumb->filename = basename($path);
	   $thumb->filepath = $path;
	   $thumb->filesize = $info['file_size'];
	   $thumb->filemime = $info['mime_type'];
	   return $thumb;
   }
  }
  return NULL;
}
hgmichna’s picture

Thanks for the replacement function, but it may be safer to copy the picture while appending _tn to the filename, for the simple reason that that will be compatible with any future version of the module.

Papayoung’s picture

This fix creates a properly-named copy to use as a thumbnail. I don't have an easy way to roll patches, but here are the specific code changes (in node_images.module, v1.7.4.2, 5.x-1.x-dev):

Line 822:

    image_scale($path, $dest_path, $width, $height);

is replaced by:

    list($src_width, $src_height, ) = $size;
    if ($src_width > $width && $src_height > $height) {
      image_scale($path, $dest_path, $width, $height);
    } else {
      file_copy($path, $dest_path, FILE_EXISTS_REPLACE);
    }

Note: I don't like creating unnecessary copies of files, even though these are going to be small ones, but in this case I think it's better to be forward-compatible than hyper-effiecent with disk space.

hgmichna’s picture

Great, thanks! Have patched the module manually with your code and will see how it goes. If any problem crops up, I will report here. Silence indicates happiness.

Can this be rolled into a future module version?

Hans-Georg

stefano73’s picture

Status: Active » Needs review
StatusFileSize
new9.61 KB

Hi guys, can you try the attached patch? It contains several fixes on file paths and thumbnail creation.
The patch is against HEAD.
Thanks.

hgmichna’s picture

Where can an ordinary user, who is not a developer, download HEAD?

Hans-Georg

hgmichna’s picture

Where can an ordinary user, who is not a developer, download HEAD?

Another question: Does this patch still create a *_tn.* file when the original image is small? If not, that would cause problems, because some other systems expect these _tn files.

Hans-Georg

stefano73’s picture

You can find the HEAD version here
The patched module still creates the _tn files when image size is small.

marcoBauli’s picture

hey all,

worked fine here out of the box with latest 5.x-1.x-dev. Was the patch integrated? cheers

stefano73’s picture

Status: Needs review » Closed (fixed)

Yes, it's already in the CVS. You can find new updates here: http://drupal.org/node/118702#comment-675694