Darrel and I were talking about the animated gif bug in IRC. This is caused by PHP's built-in GD not having the necessary libraries to deal with animated gifs.

A simple fix for this is to add an option to the field to "Enforce size restrictions without resizing" -- in other words, if this option is enabled, and I've entered 48x48 as the max dimensions for the image, if that image is not 48x48, it will kick the form back to the user with an error, rather than invoking GD to resize the image properly which is the current behaviour.

Comments

quicksketch’s picture

Status: Active » Closed (duplicate)

See http://drupal.org/node/119585 to continue discussion.

john.karahalis’s picture

I agree that this would be a useful feature, and I think I would have to disagree that http://drupal.org/node/119585 is a duplicate of this request.

john.karahalis’s picture

Project: ImageField » FileField
Version: 6.x-3.x-dev » 6.x-3.2

Moving this over to FileField.

The "automatic resize" functionality seems to be happening in filefield.module, line 757. With the following code, FileField attempts to resize an image that is too large:

<?php
        // Try to resize the image to fit the dimensions.
        elseif (image_get_toolkit() && @image_scale($file->filepath, $file->filepath, $max_width, $max_height)) {
          drupal_set_message(t('The image was resized to fit within the maximum allowed dimensions of %dimensions pixels.', array('%dimensions' => $maximum_dimensions)));

          // Clear the cached filesize and refresh the image information.
          clearstatcache();
          $info = image_get_info($file->filepath);
          $file->filesize = $info['file_size'];
        }
        else {
          $errors[] = t('The image is too large; the maximum dimensions are %dimensions pixels.', array('%dimensions' => $maximum_dimensions));
        }
?>

Would it make sense for the module to do something like this instead?

<?php
        elseif (variable_get('filefield_resize_maximum', 1) == 1 && image_get_toolkit() && @image_scale($file->filepath, $file->filepath, $max_width, $max_height)) {
          // Resize.
        }
        else {
          // Display error message.
        }
?>

Of course, an interface would need to be built to allow the user to specify whether or not he would like FileField to automatically resize images that are too large (the "filefield_resize_maximum" variable), but I think this would be an easy, useful improvement for the module.

el_reverend’s picture

Subscribing. I'd like to see that the resizing will only happen on images that fall between certain dimensions specified. All other should just be rejected.

Why on a scale? Because it is almost impossible for the laymen users to hit an exact files size. Most user will get images from a camera, maybe use bundled software to minimally edit, but with file sizes getting bigger I would have to add A LOT more ram to my server, just to keep up.