function imagecrop_scale_settings_form in Image javascript crop 7
Show the scale form for the current imagecrop.
1 string reference to 'imagecrop_scale_settings_form'
- imagecrop_cropping_page in includes/
imagecrop.admin.inc - Show the cropping page for the selected image style.
File
- includes/
imagecrop.admin.inc, line 406 - Administration tools for the imagecrop module.
Code
function imagecrop_scale_settings_form($form, $form_state, $imagecrop) {
$step = variable_get('imagecrop_scale_step', 50);
$image_width = $scale_width = $imagecrop
->getOriginalImageWidth();
$image_height = $imagecrop
->getOriginalImageHeight();
$aspect = $image_width / $image_height;
$crop_width = $imagecrop
->getWidth();
$crop_height = $imagecrop
->getHeight();
$form = array();
$options = array();
if ($step > 0) {
$options[$image_width . 'x' . $image_height] = $image_width . ' x ' . $image_height . 'px (Original)';
$scale_width -= $step;
while ($scale_width > $crop_width && $scale_width / $aspect > $crop_height) {
$scaled_height = intval($scale_width / $aspect);
$options[$scale_width . 'x' . $scaled_height] = $scale_width . ' x ' . $scaled_height . 'px (' . round($scale_width / $image_width * 100, 2) . '%)';
$scale_width -= $step;
}
}
// Set the smallest scaling option to match the width of the crop (if it fits).
$cropped_height = intval($crop_width / $aspect);
$crop_width_with_border = $crop_width + 2;
if ($crop_width != $scale_width + $step && $cropped_height >= $crop_height) {
$options[$crop_width_with_border . 'x' . $cropped_height] = $crop_width_with_border . ' x ' . $cropped_height . 'px (' . round($scale_width / $image_width * 100, 2) . '%)';
}
// only show when there are multiple scaling options available
if (count($options) > 1) {
$current_width = $imagecrop
->getScale();
$form['scaling'] = array(
'#type' => 'select',
'#options' => $options,
'#default_value' => $current_width . 'x' . floor($current_width / $aspect),
'#title' => t('Scale image'),
);
}
return $form;
}