View source
<?php
function image_imagick_shadow(stdClass $image, $color, $opacity, $sigma, $x, $y) {
$color = empty($color) ? 'none' : $color;
$shadow = clone $image->resource;
$shadow
->setImageBackgroundColor(new ImagickPixel($color));
$shadow
->shadowImage($opacity, $sigma, $x, $y);
$shadow
->compositeImage($image->resource, Imagick::COMPOSITE_OVER, $x + $sigma * 2, $y + $sigma * 2);
$dimensions = $shadow
->getImageGeometry();
$shadow
->setImagePage($dimensions['width'], $dimensions['height'], 0, 0);
$image->info['width'] = $dimensions['width'];
$image->info['height'] = $dimensions['height'];
$image->resource = $shadow;
return $image->resource;
}
function imagick_shadow_dimensions(array &$dimensions, array $data) {
if (!empty($dimensions['width']) && !empty($dimensions['height'])) {
$dimensions['width'] += $data['sigma'] * 4;
$dimensions['height'] += $data['sigma'] * 4;
}
}
function imagick_shadow($image, $data = array()) {
image_toolkit_invoke('shadow', $image, $data);
}
function imagick_shadow_form($data) {
$data = array_merge(imagick_shadow_defaults(), (array) $data);
$form['color'] = array(
'#type' => 'textfield',
'#title' => t('Color of the shadow'),
'#default_value' => $data['color'],
'#size' => 7,
'#colorpicker' => TRUE,
);
$form['opacity'] = array(
'#type' => 'textfield',
'#title' => t('Opacity'),
'#description' => t('The opacity of the shadow'),
'#default_value' => $data['opacity'],
'#size' => 3,
);
$form['sigma'] = array(
'#type' => 'textfield',
'#title' => t('Sigma'),
'#description' => t('The sigma of the shadow'),
'#default_value' => $data['sigma'],
'#size' => 3,
);
$form['x'] = array(
'#type' => 'textfield',
'#title' => t('X'),
'#description' => t('The X value of the shadow'),
'#default_value' => $data['x'],
'#size' => 3,
);
$form['y'] = array(
'#type' => 'textfield',
'#title' => t('Y'),
'#description' => t('The Y value of the shadow'),
'#default_value' => $data['y'],
'#size' => 3,
);
return $form;
}
function imagick_shadow_defaults() {
return array(
'color' => '#454545',
'opacity' => '100',
'sigma' => '25',
'x' => '0',
'y' => '0',
);
}