function imagefield_crop_field_insert in Imagefield Crop 7.2
Same name and namespace in other branches
- 7.3 imagefield_crop.module \imagefield_crop_field_insert()
Implements hook_field_insert().
File
- ./
imagefield_crop.module, line 218 - Functionality and Drupal hook implementations for the Imagefield Crop module.
Code
function imagefield_crop_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items) {
// If it's translation of the other node, we should create new image file from source and use it for processing.
if (!empty($entity->translation_source)) {
foreach ($items as &$item) {
$file = _imagefield_crop_file_to_crop($item['fid']);
$new_file = imagefield_crop_create_copy($file);
$item['fid'] = $new_file->fid;
}
}
file_field_insert($entity_type, $entity, $field, $instance, $langcode, $items);
$scale = NULL;
if (!empty($instance['widget']['settings']['resolution'])) {
list($scale['width'], $scale['height']) = explode('x', $instance['widget']['settings']['resolution']);
}
foreach ($items as &$item) {
$src = file_load($item['fid']);
if ($src && ($src->filemime != 'image/gif' || $instance['widget']['settings']['gif_processing'] == 'convert')) {
$orig = imagefield_crop_create_copy($src);
file_usage_add($orig, 'imagefield_crop', 'file', $src->fid);
_imagefield_crop_resize(drupal_realpath($orig->uri), $item, $scale, $src);
$src->uri = file_unmanaged_copy($src->uri, $src->uri);
file_save($src);
}
}
}