in function _upload_preview_create_thumbnail(&$file) there lines that are supposed to generate image preview:

$size = explode('x', variable_get('upload_preview_size', '150x150'));
if (!image_scale($file['filepath']['#value'], $path, $size[0], $size[1])) {
    // If the scaling failed, the preview is not added to the form.
    $path = NULL;
} else {
    // The image creation succeeded. Now, add the image to the preview files
    // array so that we can delete it later when it's not needed anymore.
    $previews = variable_get('upload_preview_files', array());
    $previews[$path] = time();
    variable_set('upload_preview_files', $previews);
}

this wont work if uploaded image is smaller than preview size
to solve this issue this the following modifications are needed:

$size = explode('x', variable_get('upload_preview_size', '150x150'));
$imgInfo = image_get_info($file['filepath']['#value']);
if ($imgInfo['width'] <= $size[0] && $imgInfo['height'] <= $size[1]) {
   // No scaling needed, we may use original file
   $src = $file['filepath']['#value'];
   if (!file_copy($src,$path,FILE_EXISTS_REPLACE))
       $path = null;
    } else if (!image_scale($file['filepath']['#value'], $path, $size[0], $size[1])) {
    // If the scaling failed, the preview is not added to the form.
    $path = NULL;
}
if ($path) {
    // The image creation succeeded. Now, add the image to the preview files
    // array so that we can delete it later when it's not needed anymore.
    $previews = variable_get('upload_preview_files', array());
    $previews[$path] = time();
    variable_set('upload_preview_files', $previews);
}

Comments

kkaefer’s picture

Status: Active » Fixed

Thanks for reporting this bug. I should have known, the same happened in slideshow.module.

This bug is now fixed in the development version. Get it here: http://drupal.org/node/109067

Anonymous’s picture

Status: Fixed » Closed (fixed)