function imagefield_crop_widget_preview_process in Imagefield Crop 7
Same name and namespace in other branches
- 7.3 imagefield_crop.module \imagefield_crop_widget_preview_process()
- 7.2 imagefield_crop.module \imagefield_crop_widget_preview_process()
1 string reference to 'imagefield_crop_widget_preview_process'
- imagefield_crop_widget_process in ./
imagefield_crop.module - An element #process callback for the imagefield_crop field type.
File
- ./
imagefield_crop.module, line 348 - Provide a widget to crop uploaded image.
Code
function imagefield_crop_widget_preview_process($element, &$form_state, $form) {
$file = $element['#file'];
if ($file->fid == 0) {
return $element;
}
// The widget belongs to the parent, so we got to find it first.
$parents = array_slice($element['#array_parents'], 0, -1);
$parent = drupal_array_get_nested_value($form, $parents);
$instance = field_widget_instance($parent, $form_state);
if ($instance['widget']['settings']['resolution']) {
list($width, $height) = explode('x', $instance['widget']['settings']['resolution']);
}
$image_info = image_get_info(drupal_realpath($file->uri));
$settings = array(
$parent['#id'] => array(
'preview' => array(
'orig_width' => $image_info['width'],
'orig_height' => $image_info['height'],
'width' => (int) $width,
'height' => (int) $height,
),
),
);
$element['#attached']['js'][] = array(
'data' => array(
'imagefield_crop' => $settings,
),
'type' => 'setting',
'scope' => 'header',
);
$element['#imagefield_crop'] = array(
'#file' => $element['#file'],
'#width' => $width,
'#height' => $height,
'#path' => file_create_url($file->uri),
);
return $element;
}