You are here

function _emthumb_scale_image in Embedded Media Field 6

Same name and namespace in other branches
  1. 5 contrib/emthumb/emthumb.module \_emthumb_scale_image()
  2. 6.3 contrib/emthumb/emthumb.module \_emthumb_scale_image()
  3. 6.2 contrib/emthumb/emthumb.module \_emthumb_scale_image()

Scales a newly uploaded image to fit the set resolution.

Parameters

$file: The file object representing the image. @param $resolution The width x height of an image, a string in the form of '[w]/[h]', such as '640x480'. @return The file object with the new filesize and path to scaled image.

1 call to _emthumb_scale_image()
emthumb_widget_upload_button_submit in contrib/emthumb/emthumb.module

File

contrib/emthumb/emthumb.module, line 265
Allows for custom thumbnail overrides to Embedded Media Field.

Code

function _emthumb_scale_image($file, $resolution = 0) {
  $info = image_get_info($file['filepath']);
  if ($info) {
    list($width, $height) = explode('x', $resolution);
    if ($width && $height) {
      $result = image_scale($file['filepath'], $file['filepath'], $width, $height);
      if ($result) {
        $file['filesize'] = filesize($file['filepath']);
        drupal_set_message(t('The thumbnail was resized to fit within the maximum allowed resolution of %resolution pixels', array(
          '%resolution' => $resolution,
        )));
      }
    }
  }
  return $file;
}