You are here

function _webfm_image in Web File Manager 5.2

Same name and namespace in other branches
  1. 5 webfm.module \_webfm_image()

Check an upload, if it is an image, make sure it fits within the maximum dimensions allowed.

1 call to _webfm_image()
webfm_upload in ./webfm.module
Called by upload form submit

File

./webfm.module, line 663

Code

function _webfm_image(&$file) {
  $info = image_get_info($file->filepath);
  if ($info) {
    $res = variable_get('webfm_max_resolution', 0);
    if ($res != 0) {
      list($width, $height) = explode('x', strtolower($res));
      if ($info['width'] > $width || $info['height'] > $height) {

        // Try to resize the image to fit the dimensions.
        if (image_get_toolkit() && image_scale($file->filepath, $file->filepath, $width, $height)) {
          drupal_set_message(t('The image was resized to fit within the maximum allowed resolution of %resolution pixels.', array(
            '%resolution' => variable_get('webfm_max_resolution', 0),
          )));

          // Clear the cached filesize and refresh the image information.
          clearstatcache();
          $info = image_get_info($file->filepath);
          $file->filesize = $info['file_size'];
        }
        else {
          drupal_set_message(t('The image is too large.'));
        }
      }
    }
  }
}