function imagecrop_docrop in Image javascript crop 5
Same name and namespace in other branches
- 6 imagecrop.admin.inc \imagecrop_docrop()
Callback with javascript crop.
Parameters
$fid id of file:
$presetid id of preset:
1 string reference to 'imagecrop_docrop'
- imagecrop_menu in ./
imagecrop.module - Implementation of hook_menu().
File
- ./
imagecrop.module, line 290 - Provides a javascript toolbox through an imagecache action.
Code
function imagecrop_docrop($fid, $presetid, $module = '') {
if (module_exists('jquery_interface')) {
$javascript_library = 'jquery_interface';
}
if (module_exists('jquery_ui')) {
$javascript_library = 'jquery_ui';
}
imagecrop_markup(TRUE, TRUE, $javascript_library);
if (imagecrop_action_exists() == TRUE) {
$presets = return_presets($presetid);
$file = create_image_object($fid, $presetid, $module);
if ($file != FALSE) {
$size_warning = FALSE;
// get size of temporary image
$size = getimagesize($file->dst);
$width = $size[0];
$height = $size[1];
// return warning message if crop toolbox is too big and not resizable.
if (($width < $file->crop_width || $height < $file->crop_height) && $file->resizable == 0) {
$size_warning = FALSE;
}
// add jquery interface or jquery ui
if ($javascript_library == 'jquery_interface') {
jquery_interface_add();
}
if ($javascript_library == 'jquery_ui') {
if ($file->resizable) {
jquery_ui_add(array(
'ui.resizable',
'ui.draggable',
'effects.scale',
));
}
else {
jquery_ui_add(array(
'ui.draggable',
));
}
}
// output
if ($size_warning == FALSE) {
$url = file_create_url($file->dst) . '?time=' . time();
$output .= '<div id="imagecrop_info" class="imagecrop_warning">' . t('Even if you think this crop is ok, press the submit button!') . '</div>';
$output .= theme('imagecrop', $url, $width, $height, $javascript_library, $file->resizable);
$output .= drupal_get_form('imageoffsets', $file->xoffset, $file->yoffset, $file->crop_width, $file->crop_height, $presetid, $fid, $module, $file->orig_width, $file->scale);
}
else {
$output .= '<div id="imagecrop_info" class="imagecrop_error">' . t('The crop toolbox is too big for this image.') . ' <a href="javascript:history.back();"><span class="white">' . t('Back') . '</span></a></div>';
}
return $output;
}
else {
return '<div id="imagecrop_info" class="imagecrop_error">' . t('Image to crop was not found.') . '</div>';
}
}
else {
return '<div id="imagecrop_info" class="imagecrop_error">' . t('No preset is found with the javascript_crop action so far. If you want to take advantage of this module, you will need to create at least one preset with that action.') . '</div>';
}
}