You are here

function imagefield_crop_value_callback in Imagefield Crop 7.2

Same name and namespace in other branches
  1. 7.3 imagefield_crop.module \imagefield_crop_value_callback()

Element value callback. Used to set crop area to image size, if image is smaller then output resolution, but validation isn't enabled.

Return value

array

1 string reference to 'imagefield_crop_value_callback'
imagefield_crop_field_widget_form in ./imagefield_crop.module
Implements hook_field_widget_form().

File

./imagefield_crop.module, line 978
Functionality and Drupal hook implementations for the Imagefield Crop module.

Code

function imagefield_crop_value_callback($element, $input = FALSE, $form_state) {

  // We depend on the managed file element to handle uploads.
  $return = file_field_widget_value($element, $input, $form_state);
  if ($input) {
    if ($input['fid'] == 0 && $return['fid']) {
      $return['cropbox_changed'] = 1;
    }
    $instance = field_widget_instance($element, $form_state);
    $widget_settings = $instance['widget']['settings'];
    if ($input['fid'] && $widget_settings['enforce_ratio'] && !empty($widget_settings['resolution'])) {
      $file = _imagefield_crop_file_to_crop($input['fid']);
      if ($file) {
        $image_info = image_get_info(drupal_realpath($file->uri));
        $return['cropbox_x'] = $input['cropbox_x'] < 0 ? 0 : $input['cropbox_x'];
        $return['cropbox_y'] = $input['cropbox_y'] < 0 ? 0 : $input['cropbox_y'];
        $return['cropbox_width'] = $input['cropbox_width'] > $image_info['width'] ? $image_info['width'] : $input['cropbox_width'];
        $return['cropbox_height'] = $input['cropbox_height'] > $image_info['height'] ? $image_info['height'] : $input['cropbox_height'];
      }
    }
  }
  return $return;
}