function media_crop_create_derivative in Media crop 7
Helper function to create a derivative of an image.
Parameters
object $crop_object: Anonymous object, contains data for image generation:
- uri: (string) URI of the image.
- angle: (int) Angle in degrees to rotate.
- style: (string) Name of the style to apply after rotation and cropping.
- crop_x_coordinate: (int) X coordinate of the crop.
- crop_y_coordinate: (int) Y coordinate of the crop.
- crop_width: (int) Width of the crop.
- crop_height: (int) Height of the crop.
- scale_width: (int) Width of image scale.
- scale_height: (int) Height of image scale.
- mciid: (int) Media crop instance id.
Return value
bool TRUE if the image generation is successful, FALSE otherwise.
1 call to media_crop_create_derivative()
- media_crop_get_image in ./
media_crop.module - Page callback for image generation.
File
- ./
media_crop.module, line 712 - Media crop primary module file.
Code
function media_crop_create_derivative($crop_object) {
$uri = $crop_object->uri;
$angle = $crop_object->angle;
$style = $crop_object->style;
$crop_x_coordinate = $crop_object->crop_x_coordinate;
$crop_y_coordinate = $crop_object->crop_y_coordinate;
$crop_width = $crop_object->crop_width;
$crop_height = $crop_object->crop_height;
$scale_width = $crop_object->scale_width;
$scale_height = $crop_object->scale_height;
$destination = _media_crop_get_path($crop_object->mciid, $uri);
$directory = drupal_dirname($destination);
if (!file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
watchdog('media_crop', 'Failed to create style directory: %directory', array(
'%directory' => $directory,
), WATCHDOG_ERROR);
return FALSE;
}
if (!($image = image_load($uri))) {
return FALSE;
}
_media_crop_apply_rotation($angle, $image);
_media_crop_apply_crop($crop_width, $crop_height, $crop_x_coordinate, $crop_y_coordinate, $image);
_media_crop_apply_image_style($style, $image);
_media_crop_apply_scale($scale_width, $scale_height, $image);
if (!image_save($image, $destination)) {
if (file_exists($destination)) {
watchdog('media_crop', 'Cached image file %destination already exists. There may be an issue with your rewrite configuration.', array(
'%destination' => $destination,
), WATCHDOG_ERROR);
}
return FALSE;
}
return TRUE;
}