View source
<?php
function image_imagick_overlay(stdClass $image, stdClass $layer, $x, $y, $alpha = 100, $reverse = FALSE) {
$path = drupal_realpath($layer->source);
$overlay = new Imagick($path);
if ($alpha != 100) {
$overlay
->setImageFormat('png');
imagick_coloroverlay_set_opacity($overlay, $alpha);
}
return $image->resource
->compositeImage($overlay, Imagick::COMPOSITE_DEFAULT, $x, $y);
}
function image_imagick_coloroverlay(stdClass $image, $data = array()) {
$color = $data['RGB']['HEX'];
$color = empty($color) ? 'none' : $color;
$overlay = new Imagick();
$overlay
->newImage($image->info['width'], $image->info['height'], new ImagickPixel($color));
return $image->resource
->compositeImage($overlay, Imagick::COMPOSITE_DEFAULT, 0, 0);
}
function image_imagick_coloroverlay_alpha(stdClass $image, $color, $alpha) {
$color = empty($color) ? 'none' : $color;
$overlay = new Imagick();
$overlay
->newImage($image->info['width'], $image->info['height'], new ImagickPixel($color));
$overlay
->setImageFormat('png');
imagick_coloroverlay_set_opacity($overlay, $alpha);
return $image->resource
->compositeImage($overlay, Imagick::COMPOSITE_DEFAULT, 0, 0);
}
function imagick_coloroverlay_alpha($image, $data = array()) {
image_toolkit_invoke('coloroverlay_alpha', $image, $data);
}
function imagick_coloroverlay_alpha_form($data) {
$data = array_merge(imagick_coloroverlay_defaults(), (array) $data);
$form['HEX'] = array(
'#type' => 'textfield',
'#title' => t('HEX'),
'#default_value' => $data['HEX'],
'#size' => 7,
'#colorpicker' => TRUE,
);
$form['alpha'] = array(
'#type' => 'textfield',
'#title' => t('Opacity'),
'#description' => t('Opacity of the color overlay in percents.'),
'#default_value' => $data['alpha'],
'#size' => 3,
);
return $form;
}
function imagick_coloroverlay_defaults() {
return array(
'HEX' => '#FFFFFF',
'alpha' => 50,
);
}
function imagick_coloroverlay_set_opacity($image, $alpha) {
$alpha = $alpha / 100;
if (method_exists($image, 'setImageOpacity')) {
$image
->setImageOpacity($alpha);
}
else {
$image
->setImageAlpha($alpha);
}
}