function _simplecrop_save_crop_from_values in SimpleCrop 7
Saves submitted image crop value to the database.
1 call to _simplecrop_save_crop_from_values()
- simplecrop_field_attach_submit in includes/
simplecrop.field.inc - Implements hook_field_attached_submit().
File
- includes/
simplecrop.field.inc, line 662 - Contains information about field widget and related functions.
Code
function _simplecrop_save_crop_from_values($value) {
// If image for some unknown reasons doesn't have file ID,
// then we can't do nothing here to process a submit request.
if (empty($value['fid'])) {
return;
}
// Ensure that we have all required data to save the crop.
if (!empty($value['data']) && !empty($value['scaled_size']) && !empty($value['original_size'])) {
// Unscale coordinates from scaled image to original.
$x = round($value['original_size']['width'] / $value['scaled_size']['width'] * $value['data']['x']);
$y = round($value['original_size']['height'] / $value['scaled_size']['height'] * $value['data']['y']);
$x2 = round($value['original_size']['width'] / $value['scaled_size']['width'] * $value['data']['x2']);
$y2 = round($value['original_size']['height'] / $value['scaled_size']['height'] * $value['data']['y2']);
// Save crop data for each image.
$file = file_load($value['fid']);
simplecrop_crop_save($file->uri, array(
'x' => $x,
'y' => $y,
'x2' => $x2,
'y2' => $y2,
));
// Flush image styles for this path to regenerate image.
image_path_flush($file->uri);
}
}