first import

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-08 11:40:19 +02:00
commit 1bc61b12ad
8435 changed files with 1582817 additions and 0 deletions

View File

@@ -0,0 +1,852 @@
<?php
/**
* @file Helper functions for the text2canvas action for imagecache
*
* @author Dan Morrison http://coders.co.nz
*
* Individually configurable rounded corners logic contributed by canaryMason
* 2009 03 http://drupal.org/node/402112
*
* Better algorithm for trimming rounded corners from donquixote
* 2009 09 http://drupal.org/node/564036
*
*/
if (!function_exists('image_overlay')) {
module_load_include('inc', 'imagecache_actions', 'image_overlay');
}
if (!function_exists('imagecache_actions_pos_form')) {
module_load_include('inc', 'imagecache_actions', 'utility-form');
}
if (!function_exists('imagecache_actions_keyword_filter')) {
module_load_include('inc', 'imagecache_actions', 'utility');
}
////////////////////////////////////////////////
// IMAGEMASK
/**
* Implements the form callback for the image mask effect.
*
* @param array $data
* array of settings for this action.
* @return array
* A form definition.
*/
function canvasactions_imagemask_form($data) {
// @todo: add offset/positioning/scaling support - currently the mask is applied to the supplied image without resizing and positioned at (0,0)
$form = array();
$form['effect_help_text'] = array(
'#type' => 'item',
'#title' => t('Image mask'),
'#description' => t('This effect will add (or replace) a transparency channel to your image. The mask file should be a grayscale image where black is fully transparent and white is fully opaque. The referenced mask will be applied to the top left of the image.'),
);
$form['path'] = array(
'#type' => 'textfield',
'#title' => t('Mask file name'),
'#default_value' => isset($data['path']) ? $data['path'] : '',
'#description' => imagecache_actions_file_field_description(),
'#element_validate' => array('imagecache_actions_validate_file'),
);
return $form;
}
/**
* Implements the summary theme function for the image mask effect.
*/
function theme_canvasactions_imagemask_summary($variables) {
$data = $variables['data'];
return 'file: ' . $data['path'];
}
/**
* Implement the effect callback for the image mask effect.
*
* @param object $image
* @param array $data
*
* @return bool
*/
function canvasactions_imagemask_image(&$image, $data = array()) {
$mask = imagecache_actions_image_load($data['path'], $image->toolkit);
if ($mask) {
// @todo: (sydneyshan) Consider best way to add offset support - I assume we
// would position the mask somewhere (top/left/offset px etc) and choose if
// the surrounding area is white or black (opaque or transparent) using an
// extra form element (radio). Assess existing positioning code first to
// reduce duplication of code. Pass the results to the following function as
// array($mask, $data). Perhaps add a 'scale mask to fit image'/'scale image
// to fit mask'/'no scale' radio group?
return image_toolkit_invoke('imagemask', $image, array($mask));
}
return FALSE;
}
/**
* Implements the image mask effect using the GD toolkit.
*
* $image object
* Image object containing the GD image resource to operate on.
* $mask object
* An image object containing the image to use as mask.
*/
function image_gd_imagemask($image, $mask) {
$newPicture = imagecreatetruecolor($image->info['width'], $image->info['height']);
imagesavealpha($newPicture, TRUE);
imagealphablending($newPicture, TRUE);
$transparent = imagecolorallocatealpha($newPicture, 0, 0, 0, 127);
imagefill($newPicture, 0, 0, $transparent);
// Perform pixel-based alpha map application
for ($x = 0; $x < $image->info['width']; $x++) {
for ($y = 0; $y < $image->info['height']; $y++) {
// Deal with images with mismatched sizes
if ($x >= $mask->info['width'] || $y >= $mask->info['height']) {
imagesetpixel($newPicture, $x, $y, $transparent);
}
else {
$alpha = imagecolorsforindex($mask->resource, imagecolorat($mask->resource, $x, $y));
$alpha = 127 - floor($alpha['red'] / 2);
$color = imagecolorsforindex($image->resource, imagecolorat($image->resource, $x, $y));
imagesetpixel($newPicture, $x, $y, imagecolorallocatealpha($newPicture, $color['red'], $color['green'], $color['blue'], $alpha));
}
}
}
// Copy back to original picture
imagedestroy($image->resource);
$image->resource = $newPicture;
return TRUE;
}
/**
* Implements the image mask effect using the imagemagick toolkit.
*
* $image object
* Image object containing a.o. the image to operate on.
* $mask object
* An image object containing the image to use as mask.
*/
function image_imagemagick_imagemask($image, $mask) {
$image->ops[] = escapeshellarg($mask->source) . ' -alpha Off -compose CopyOpacity -composite';
return TRUE;
}
////////////////////////////////////////////////
/**
* Implementation of imagecache_hook_form()
*
* Settings for preparing a canvas.
*
* @param $data array of settings for this action
* @return a form definition
*/
function canvasactions_definecanvas_form($data) {
module_load_include('inc', 'imagecache_actions', 'utility-color');
$defaults = array(
'RGB' => array(
'HEX' => '#333333',
),
'under' => TRUE,
'exact' => array(
'width' => '',
'height' => '',
'xpos' => 'center',
'ypos' => 'center',
),
'relative' => array(
'leftdiff' => '',
'rightdiff' => '',
'topdiff' => '',
'bottomdiff' => '',
),
);
$data = array_merge($defaults, (array) $data);
$form = array(
'RGB' => imagecache_rgb_form($data['RGB']),
'help' => array(
'#type' => 'markup',
'#value' => t('Enter no color value for transparent. This will have the effect of adding clear margins around the image.'),
'#prefix' => '<p>',
'#suffix' => '</p>',
),
'under' => array(
'#type' => 'checkbox',
'#title' => t('Resize canvas <em>under</em> image (possibly cropping)'),
'#default_value' => $data['under'],
'#description' => t('If <em>not</em> set, this will create a solid flat layer, probably totally obscuring the source image'),
),
);
$form['info'] = array('#value' => t('Enter values in ONLY ONE of the below options. Either exact or relative. Most values are optional - you can adjust only one dimension as needed. If no useful values are set, the current base image size will be used.'));
$form['exact'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#title' => 'Exact size',
'help' => array(
'#type' => 'markup',
'#value' => t('Set the canvas to a precise size, possibly cropping the image. Use to start with a known size.'),
'#prefix' => '<p>',
'#suffix' => '</p>',
),
'width' => array(
'#type' => 'textfield',
'#title' => t('Width'),
'#default_value' => $data['exact']['width'],
'#description' => t('Enter a value in pixels or percent'),
'#size' => 5,
),
'height' => array(
'#type' => 'textfield',
'#title' => t('Height'),
'#default_value' => $data['exact']['height'],
'#description' => t('Enter a value in pixels or percent'),
'#size' => 5,
),
);
$form['exact'] = array_merge($form['exact'], imagecache_actions_pos_form($data['exact']));
if (!$data['exact']['width'] && !$data['exact']['height']) {
$form['exact']['#collapsed'] = TRUE;
}
$form['relative'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#title' => t('Relative size'),
'help' => array(
'#type' => 'markup',
'#value' => '<p>' . t('Set the canvas to a relative size, based on the current image dimensions. Use to add simple borders or expand by a fixed amount. Negative values may crop the image.') . '</p>',
),
'leftdiff' => array(
'#type' => 'textfield',
'#title' => t('left difference'),
'#default_value' => $data['relative']['leftdiff'],
'#size' => 6,
'#description' => t('Enter an offset in pixels.'),
),
'rightdiff' => array(
'#type' => 'textfield',
'#title' => t('right difference'),
'#default_value' => $data['relative']['rightdiff'],
'#size' => 6,
'#description' => t('Enter an offset in pixels.'),
),
'topdiff' => array(
'#type' => 'textfield',
'#title' => t('top difference'),
'#default_value' => $data['relative']['topdiff'],
'#size' => 6,
'#description' => t('Enter an offset in pixels.'),
),
'bottomdiff' => array(
'#type' => 'textfield',
'#title' => t('bottom difference'),
'#default_value' => $data['relative']['bottomdiff'],
'#size' => 6,
'#description' => t('Enter an offset in pixels.'),
),
);
if (!$data['relative']['leftdiff'] && !$data['relative']['rightdiff'] && !$data['relative']['topdiff'] && !$data['relative']['bottomdiff']) {
$form['relative']['#collapsed'] = TRUE;
}
$form['#submit'][] = 'canvasactions_definecanvas_form_submit';
return $form;
}
/**
* Implementation of theme_hook() for imagecache_ui.module
*/
function theme_canvasactions_definecanvas_summary($variables) {
$data = $variables['data'];
if ($data['exact']['width'] || $data['exact']['height']) {
$w = !empty($data['exact']['width']) ? $data['exact']['width'] : '100%';
$h = !empty($data['exact']['height']) ? $data['exact']['height'] : '100%';
$x = !empty($data['exact']['xpos']) ? $data['exact']['xpos'] : '0';
$y = !empty($data['exact']['ypos']) ? $data['exact']['ypos'] : '0';
$output = "{$w}x{$h} ($x, $y)";
}
else {
$output = ' left:' . $data['relative']['leftdiff'];
$output .= ' right:' . $data['relative']['rightdiff'];
$output .= ' top:' . $data['relative']['topdiff'];
$output .= ' bottom:' . $data['relative']['bottomdiff'];
}
$output .= theme('imagecacheactions_rgb', array('RGB' => $data['RGB']));
$output .= ($data['under']) ? t(" <b>under</b> image ") : t(" <b>over</b> image ");
return $output;
}
/**
* Implementation of hook_image()
*
* Creates a solid background canvas
*
* Process the imagecache action on the passed image
*
* @param $image
* array defining an image file, including :
*
* $image- >source as the filename,
*
* $image->info array
*
* $image->resource handle on the image object
*/
function canvasactions_definecanvas_effect($image, $data) {
// May be given either exact or relative dimensions.
if ($data['exact']['width'] || $data['exact']['height']) {
// Allows only one dimension to be used if the other is unset.
if (!$data['exact']['width']) {
$data['exact']['width'] = $image->info['width'];
}
if (!$data['exact']['height']) {
$data['exact']['height'] = $image->info['height'];
}
$targetsize['width'] = imagecache_actions_percent_filter($data['exact']['width'], $image->info['width']);
$targetsize['height'] = imagecache_actions_percent_filter($data['exact']['height'], $image->info['height']);
$targetsize['left'] = image_filter_keyword($data['exact']['xpos'], $targetsize['width'], $image->info['width']);
$targetsize['top'] = image_filter_keyword($data['exact']['ypos'], $targetsize['height'], $image->info['height']);
}
else {
// calculate relative size
$targetsize['width'] = $image->info['width'] + $data['relative']['leftdiff'] + $data['relative']['rightdiff'];
$targetsize['height'] = $image->info['height'] + $data['relative']['topdiff'] + $data['relative']['bottomdiff'];
$targetsize['left'] = $data['relative']['leftdiff'];
$targetsize['top'] = $data['relative']['topdiff'];
}
// convert from hex (as it is stored in the UI)
if ($data['RGB']['HEX'] && $deduced = imagecache_actions_hex2rgba($data['RGB']['HEX'])) {
$data['RGB'] = array_merge($data['RGB'], $deduced);
}
// All the maths is done, now defer to the api toolkits;
$data['targetsize'] = $targetsize;
$success = image_toolkit_invoke('definecanvas', $image, array($data));
if ($success) {
$image->info['width'] = $targetsize['width'];
$image->info['height'] = $targetsize['height'];
}
return $success;
}
function canvasactions_definecanvas_dimensions(array &$dimensions, array $data) {
// May be given either exact or relative dimensions.
if ($data['exact']['width'] || $data['exact']['height']) {
// Allows only one dimension to be used if the other is unset.
if (!$data['exact']['width']) {
$data['exact']['width'] = $dimensions['width'];
}
if (!$data['exact']['height']) {
$data['exact']['height'] = $dimensions['height'];
}
$dimensions['width'] = imagecache_actions_percent_filter($data['exact']['width'], $dimensions['width']);
$dimensions['height'] = imagecache_actions_percent_filter($data['exact']['height'], $dimensions['height']);
}
else {
// calculate relative size
$dimensions['width'] = $dimensions['width'] + $data['relative']['leftdiff'] + $data['relative']['rightdiff'];
$dimensions['height'] = $dimensions['height'] + $data['relative']['topdiff'] + $data['relative']['bottomdiff'];
}
}
/**
* Draw a color (or transparency) behind an image
*
* $targetsize is an array expected to contain a width,height and a left,top
* offset.
*/
function image_gd_definecanvas($image, $data = array()) {
$targetsize = $data['targetsize'];
$RGB = $data['RGB'];
$newcanvas = imagecreatetruecolor($targetsize['width'], $targetsize['height']);
imagesavealpha($newcanvas, TRUE);
imagealphablending($newcanvas, FALSE);
imagesavealpha($image->resource, TRUE);
if ($RGB['HEX']) {
// Set color, allow it to define transparency, or assume opaque.
$background = imagecolorallocatealpha($newcanvas, $RGB['red'], $RGB['green'], $RGB['blue'], $RGB['alpha']);
}
else {
// No color, attempt transparency, assume white
$background = imagecolorallocatealpha($newcanvas, 255, 255, 255, 127);
}
imagefilledrectangle($newcanvas, 0, 0, $targetsize['width'], $targetsize['height'], $background);
# imagealphablending($newcanvas, TRUE);
if ($data['under']) {
$canvas_object = (object) array(
'resource' => $newcanvas,
'info' => array(
'width' => $targetsize['width'],
'height' => $targetsize['height'],
'mime_type' => $image->info['mime_type'],
'extension' => $image->info['extension'],
),
'toolkit' => $image->toolkit,
);
image_overlay($image, $canvas_object, $targetsize['left'], $targetsize['top'], 100, TRUE);
}
else {
$image->resource = $newcanvas;
}
return TRUE;
}
/**
* Draw a color (or transparency) behind an image
* $targetsize is an array expected to contain a width,height and a left,top
* offset.
*
* See http://www.imagemagick.org/script/command-line-options.php#extent
* @todo: reset gravity?
*/
function image_imagemagick_definecanvas($image, $data = array()) {
$backgroundcolor = $data['RGB']['HEX'] != '' ? '#' . $data['RGB']['HEX'] : 'None';
$image->ops[] = '-background ' . escapeshellarg($backgroundcolor);
$compose_operator = $data['under'] ? 'src-over' : 'dst-over';
$image->ops[] = "-compose $compose_operator";
$targetsize = $data['targetsize'];
$geometry = sprintf('%dx%d', $targetsize['width'], $targetsize['height']);
if ($targetsize['left'] || $targetsize['top']) {
$geometry .= sprintf('%+d%+d', -$targetsize['left'], -$targetsize['top']);
}
$image->ops[] = "-extent $geometry";
return TRUE;
}
////////////////////////////////////////////////
/**
* Place a given image under the current canvas
*
* Implementation of imagecache_hook_form()
*
* @param $data array of settings for this action
* @return a form definition
*/
function canvasactions_canvas2file_form($data) {
// if (image_get_toolkit() != 'gd') {
// drupal_set_message('Overlays are not currently supported by using imagemagick. This effect requires GD image toolkit only.', 'warning');
// }
$defaults = array(
'xpos' => '0',
'ypos' => '0',
'alpha' => '100',
'path' => '',
'dimensions' => 'original',
);
$data = array_merge($defaults, (array) $data);
$form = imagecache_actions_pos_form($data);
$form['alpha'] = array(
'#type' => 'textfield',
'#title' => t('opacity'),
'#default_value' => $data['alpha'],
'#size' => 6,
'#description' => t('Opacity: 0-100. Be aware that values other than 100% may be slow to process.'),
);
$form['path'] = array(
'#type' => 'textfield',
'#title' => t('file name'),
'#default_value' => $data['path'],
'#description' => imagecache_actions_file_field_description(),
'#element_validate' => array('imagecache_actions_validate_file'),
);
$form['dimensions'] = array(
'#type' => 'radios',
'#title' => t('final dimensions'),
'#default_value' => $data['dimensions'],
'#options' => array(
'original' => 'original (dimensions are retained)',
'background' => 'background (image will be forced to match the size of the background)',
'minimum' => 'minimum (image may be cropped)',
'maximum' => 'maximum (image may end up with gaps)',
),
'#description' => t('What to do when the background image is a different size from the source image. Backgrounds are not tiled, but may be arbitrarily large.'),
);
return $form;
}
/**
* Implementation of theme_hook() for imagecache_ui.module
*/
function theme_canvasactions_canvas2file_summary($variables) {
$data = $variables['data'];
$file = $data['path'];
return "xpos:{$data['xpos']} , ypos:{$data['ypos']} alpha:{$data['alpha']}%. file: $file, dimensions:{$data['dimensions']}";
}
/**
* Place the source image on the current background
*
* Implementation of hook_image()
*
* Note - this is currently incompatable with imagemagick, due to the way it
* addresses $image->resource directly - a gd only thing.
*
* @param $image
* @param $data
*/
function canvasactions_canvas2file_image(&$image, $data = array()) {
$underlay = imagecache_actions_image_load($data['path'], $image->toolkit);
if ($underlay) {
// To handle odd sizes, we will resize/crop the background image to the
// desired dimensions before starting the merge. The built-in
// imagecopymerge, and the watermark library both do not allow overlays to
// be bigger than the target.
// Adjust size
$crop_rules = array(
'xoffset' => 0,
'yoffset' => 0,
);
if (empty($data['dimensions'])) {
$data['dimensions'] = 'original';
}
switch ($data['dimensions']) {
case 'original':
// If the underlay is smaller than the target size,
// then when preparing the underlay by cropping it,
// the offsets may need to be negative
// which will produce a 'cropped' image larger than the original.
// In this case, we need to calculate the position of the bg image
// in relation to the space it will occupy under the top layer
#$crop_rules['xoffset'] = $underlay->info['width'] - $image->info['width'] ;
$crop_rules['width'] = $image->info['width'];
$crop_rules['height'] = $image->info['height'];
break;
case 'background':
$crop_rules['width'] = $underlay->info['width'];
$crop_rules['height'] = $underlay->info['height'];
break;
case 'minimum':
$crop_rules['width'] = min($underlay->info['width'], $image->info['width']);
$crop_rules['height'] = min($underlay->info['height'], $image->info['height']);
break;
case 'maximum':
$crop_rules['width'] = max($underlay->info['width'], $image->info['width']);
$crop_rules['height'] = max($underlay->info['height'], $image->info['height']);
break;
}
// imageapi crop assumes upsize is legal.
// Crop both before processing to avoid unwanted processing.
image_crop_effect($underlay, $crop_rules);
# BUG - this doesn't position either
// Actually this fails because imagecache_crop fills it with solid color when 'cropping' to a larger size.
#imagecache_crop_image($image, $crop_rules);
#dpm(get_defined_vars());
// This func modifies the underlay image by ref, placing the current canvas on it
if (image_overlay($image, $underlay, $data['xpos'], $data['ypos'], $data['alpha'], TRUE)) {
#$image->resource = $underlay->resource;
$image = $underlay;
return TRUE;
}
}
return FALSE;
}
/**
* Image dimensions callback; canvas2file (underlay/background).
*
* @param array $dimensions
* Dimensions to be modified - an associative array containing the items
* 'width' and 'height' (in pixels).
* @param $data
* An associative array containing the effect data.
*/
function canvasactions_canvas2file_dimensions(array &$dimensions, array $data) {
if ($data['dimensions'] !== 'original') {
$underlay = imagecache_actions_image_load($data['path']);
if ($underlay) {
// If the new dimensions are taken from the background, we don't need to
// know the original dimensions, we can just set the new dimensions to the
// dimensions of the background. Otherwise, we need to know the old
// dimensions. If unknown we have to leave them unknown.
switch ($data['dimensions']) {
case 'background':
$dimensions['width'] = $underlay->info['width'];
$dimensions['height'] = $underlay->info['height'];
break;
case 'minimum':
$dimensions['width'] = isset($dimensions['width']) ? min($underlay->info['width'], $dimensions['width']) : NULL;
$dimensions['height'] = isset($dimensions['height']) ? min($underlay->info['height'], $dimensions['height']) : NULL;
break;
case 'maximum':
$dimensions['width'] = isset($dimensions['width']) ? max($underlay->info['width'], $dimensions['width']) : NULL;
$dimensions['height'] = isset($dimensions['height']) ? max($underlay->info['height'], $dimensions['height']) : NULL;
break;
}
}
}
}
/**
* Place a given image on top of the current canvas
*
* Implementation of imagecache_hook_form()
*
* @param $data array of settings for this action
* @return a form definition
*/
function canvasactions_file2canvas_form($data) {
$defaults = array(
'xpos' => '',
'ypos' => '',
'alpha' => '100',
'path' => '',
);
$data = array_merge($defaults, (array) $data);
$form = array(
'help' => array(
'#type' => 'markup',
'#value' => t('Note that using a transparent overlay that is larger than the source image may result in unwanted results - a solid background.'),
),
);
$form += imagecache_actions_pos_form($data);
$form['alpha'] = array(
'#type' => 'textfield',
'#title' => t('opacity'),
'#default_value' => $data['alpha'],
'#size' => 6,
'#description' => t('Opacity: 0-100. <b>Warning:</b> Due to a limitation in the GD toolkit, using an opacity other than 100% requires the system to use an algorithm that\'s much slower than the built-in functions. If you want partial transparency, you are better to use an already-transparent png as the overlay source image.'),
);
$form['path'] = array(
'#type' => 'textfield',
'#title' => t('file name'),
'#default_value' => $data['path'],
'#description' => imagecache_actions_file_field_description(),
'#element_validate' => array('imagecache_actions_validate_file'),
);
return $form;
}
/**
* Implementation of theme_hook() for imagecache_ui.module
*/
function theme_canvasactions_file2canvas_summary($variables) {
$data = $variables['data'];
return '<strong>' . $data['path'] . '</strong> x:' . $data['xpos'] . ', y:' . $data['ypos'] . ' alpha:' . (@$data['alpha'] ? $data['alpha'] : 100) . '%';
}
/**
* Place the source image on the current background
*
* Implementation of hook_image()
*
*
* @param $image
* @param $data
*/
function canvasactions_file2canvas_image($image, $data = array()) {
$overlay = imagecache_actions_image_load($data['path']);
if ($overlay) {
if (!isset($data['alpha'])) {
$data['alpha'] = 100;
}
return image_overlay($image, $overlay, $data['xpos'], $data['ypos'], $data['alpha']);
}
return FALSE;
}
///////////////////////////////////////////////////////////////////
/**
* Place the source image on top of the current canvas
*
* Implementation of imagecache_hook_form()
*
*
*
* @param $data array of settings for this action
* @return a form definition
*/
function canvasactions_source2canvas_form($data) {
$defaults = array(
'xpos' => '',
'ypos' => '',
'alpha' => '100',
'path' => '',
);
$data = array_merge($defaults, (array) $data);
$form = imagecache_actions_pos_form($data);
$form['alpha'] = array(
'#type' => 'textfield',
'#title' => t('opacity'),
'#default_value' => $data['alpha'],
'#size' => 6,
'#description' => t('Opacity: 0-100.'),
);
return $form;
}
/**
* Implementation of theme_hook() for imagecache_ui.module
*/
function theme_canvasactions_source2canvas_summary($variables) {
$data = $variables['data'];
return 'xpos:' . $data['xpos'] . ', ypos:' . $data['ypos'] . ' alpha:' . $data['alpha'] . '%';
}
/**
* Place the source image on the current background
*
* Implementation of hook_image()
*
*
* @param $image
* @param $data
*/
function canvasactions_source2canvas_image($image, $data = array()) {
$overlay = image_load($image->source, $image->toolkit);
return image_overlay($image, $overlay, $data['xpos'], $data['ypos'], $data['alpha']);
}
/**
* Implements the image effect form callback for the aspect switcher effect.
*
* @param array $data
* Array of settings for this action
* @return array
* The form definition
*/
function canvasactions_aspect_form($data) {
$defaults = array(
'ratio_adjustment' => 1,
'portrait' => NULL,
'landscape' => NULL,
);
$data = array_merge($defaults, (array) $data);
$form = array(
'help' => array(
'#type' => 'markup',
'#value' => t('You must create the two presets to use <em>before</em> enabling this process.'),
)
);
$styles = image_style_options(TRUE);
// @todo: remove the current style to prevent (immediate) recursion?
$form['portrait'] = array(
'#type' => 'select',
'#title' => t('Style to use if the image is portrait (vertical)'),
'#default_value' => $data['portrait'],
'#options' => $styles,
'#description' => t('If you choose none, no extra processing will be done.'),
);
$form['landscape'] = array(
'#type' => 'select',
'#title' => t('Style to use if the image is landscape (horizontal)'),
'#default_value' => $data['landscape'],
'#options' => $styles,
'#description' => t('If you choose none, no extra processing will be done.'),
);
$form['ratio_adjustment'] = array(
'#type' => 'textfield',
'#title' => t('Ratio Adjustment (advanced)'),
'#size' => 3,
'#default_value' => $data['ratio_adjustment'],
'#description' => t("
This allows you to bend the rules for how different the proportions need to be to trigger the switch.
<br/>If the (width/height)*n is greater than 1, use 'landscape', otherwise use 'portrait'.
<br/>When n = 1 (the default) it will switch between portrait and landscape modes.
<br/>If n > 1, images that are slightly wide will still be treated as portraits.
If n < 1 then blunt portraits will be treated as landscape.
"),
);
return $form;
}
/**
* Implements the summary theme callback for the aspect switcher effect.
*
* @param array $variables
*
* @return string
*/
function theme_canvasactions_aspect_summary($variables) {
$data = $variables['data'];
$ratio_adjustment = '';
if ($data['ratio_adjustment'] != 1) {
$ratio_adjustment = " (switch at 1:{$data['ratio_adjustment']})";
}
return 'Portrait size: <strong>' . $data['portrait'] . '</strong>. Landscape size: <strong>' . $data['landscape'] . '</strong>' . $ratio_adjustment;
}
/**
* Implements the image effect callback for the aspect switcher effect.
*
* @param object $image
* @param array $data
*
* @return bool
*/
function canvasactions_aspect_image($image, $data = array()) {
$ratio_adjustment = isset($data['ratio_adjustment']) ? floatval( $data['ratio_adjustment']) : 1;
$aspect = $image->info['width'] / $image->info['height'];
// width / height * adjustment. If > 1, it's wide.
$style_name = (($aspect * $ratio_adjustment) > 1) ? $data['landscape'] : $data['portrait'];
if (empty($style_name)) {
// Do nothing. just return what we've got.
return TRUE;
}
$style = image_style_load($style_name);
if (empty($style)) {
// Required preset has gone missing?
watchdog('imagecache_canvasactions', "When running 'aspect' action, I was unable to load sub-action %style_name. Either it's been deleted or the DB needs an update", array('%style_name' => $style_name), WATCHDOG_ERROR);
return FALSE;
}
// Run the preset actions ourself.
foreach ($style['effects'] as $sub_effect) {
image_effect_apply($image, $sub_effect);
}
return TRUE;
}
/**
* Implements the dimension callback for the aspect switcher effect.
*
* @param array $dimensions
* Dimensions to be modified - an associative array containing the items
* 'width' and 'height' (in pixels).
* @param array $data
* An associative array containing the effect data.
*/
function canvasactions_aspect_dimensions(array &$dimensions, array $data) {
if (empty($dimensions['width']) || empty($dimensions['height'])) {
return;
}
$ratio_adjustment = isset($data['ratio_adjustment']) ? floatval( $data['ratio_adjustment']) : 1;
$aspect = $dimensions['width'] / $dimensions['height'];
$style_name = (($aspect * $ratio_adjustment) > 1) ? $data['landscape'] : $data['portrait'];
image_style_transform_dimensions($style_name, $dimensions);
}

View File

@@ -0,0 +1,31 @@
name = Imagecache Canvas Actions
description = Actions for manipulating image canvases layers, including watermark and background effect. Also an aspect switcher (portrait/landscape)
package = Media
core = 7.x
dependencies[] = imagecache_actions
dependencies[] = image
files[] = canvasactions.inc
files[] = imagecache_canvasactions.install
files[] = imagecache_canvasactions.module
files[] = rounded_corners.inc
files[] = tests/cheap_dropshadow.imagecache_preset.inc
files[] = tests/keyword_positioning.imagecache_preset.inc
files[] = tests/positioned_underlay.imagecache_preset.inc
files[] = tests/rotate_alpha.imagecache_preset.inc
files[] = tests/rotate_alpha_gif.imagecache_preset.inc
files[] = tests/rotate_scale.imagecache_preset.inc
files[] = tests/rotate_scale_alpha.imagecache_preset.inc
files[] = tests/rounded.imagecache_preset.inc
files[] = tests/rounded_bl.imagecache_preset.inc
files[] = tests/rounded_flattened.imagecache_preset.inc
files[] = tests/watermark_100.imagecache_preset.inc
files[] = tests/watermark_50.imagecache_preset.inc
; Information added by drupal.org packaging script on 2012-12-04
version = "7.x-1.1"
core = "7.x"
project = "imagecache_actions"
datestamp = "1354653754"

View File

@@ -0,0 +1,27 @@
<?php
/**
* @file Set up new canvas actions. Tell imagecache.module about them
*/
/**
* Need to flush the cache when this module is enabled or disabled
*/
function imagecache_canvasactions_install() {
if (function_exists('imagecache_action_definitions') ) {
imagecache_action_definitions(TRUE);
}
cache_clear_all('imagecache_actions', 'cache');
drupal_set_message(t('Additional image style actions should now be available in the presets !settings_link', array('!settings_link' => l(t('settings'), 'admin/config/media/image-styles'))));
}
/**
* @todo Please document this function.
* @see http://drupal.org/node/1354
*/
function imagecache_canvasactions_uninstall() {
if (function_exists('imagecache_action_definitions') ) {
imagecache_action_definitions(TRUE);
}
cache_clear_all('imagecache_actions', 'cache');
}

View File

@@ -0,0 +1,188 @@
<?php
/**
* @file A collection of canvas (layer) type manipulations for imagecache -
* including "Watermark"
*
* Based on first draft of the code by Dimm (imagecache.module 5--1)
* http://drupal.org/node/184816
*
* Rewritten and ported to Imagecache actions API (imagecache.module 5--2) by
* dman http://coders.co.nz/
*
*
* Notes about imagecache action extensions. For each action:
*
* 1: Implement imagecache_HOOK_form($formdata) to define the config form.
*
* 1a: Implement theme_imagecache_HOOK_form if needed - optional
*
* 2: Implement imagecache_HOOK_image($image, $data) to DO the process
*
* 3: Implement theme_imagecache_HOOK($element) to return a text description of
* the setting
*
* 4: Declare the action in HOOK_imagecache_actions()
*
*
* API ref for hook_image()
*
* @param $image array defining an image file, including :
*
* $image- >source as the filename,
*
* $image->info array
*
* $image->resource handle on the image object
*
* @param $action array of settings as defined in your form.
*
*/
// During devel, caching is pointless. Flush it
// imagecache_action_definitions(TRUE);
if (! function_exists('imagecache_actions_calculate_relative_position') ) {
module_load_include('inc', 'imagecache_canvasactions', 'utility');
}
// @todo There doesn't seem to be a way to specify a file in hook_image_effect_info
// so placing this here for the time being.
module_load_include('inc', 'imagecache_canvasactions', 'canvasactions');
module_load_include('inc', 'imagecache_canvasactions', 'rounded_corners');
// imageapi extensions
module_load_include('inc', 'imagcache_actions', 'image_overlay.inc');
function imagecache_canvasactions_image_effect_info() {
$effects = array();
$effects['canvasactions_definecanvas'] = array(
'label' => t('Define canvas'),
'help' => t('Define the size of the working canvas and background color, this controls the dimensions of the output image.'),
'effect callback' => 'canvasactions_definecanvas_effect',
'dimensions callback' => 'canvasactions_definecanvas_dimensions',
'form callback' => 'canvasactions_definecanvas_form',
'summary theme' => 'canvasactions_definecanvas_summary',
);
$effects['canvasactions_imagemask'] = array(
'label' => t('Image mask'),
'help' => t(' Choose the file image you wish to use as a mask, and apply it to the canvas.'),
'effect callback' => 'canvasactions_imagemask_image',
'dimensions passthrough' => TRUE,
'form callback' => 'canvasactions_imagemask_form',
'summary theme' => 'canvasactions_imagemask_summary',
);
$effects['canvasactions_file2canvas'] = array(
'label' => t('Overlay (watermark)'),
'help' => t('Choose the file image you wish to use as an overlay, and position it in a layer on top of the canvas.'),
'effect callback' => 'canvasactions_file2canvas_image',
'dimensions passthrough' => TRUE,
'form callback' => 'canvasactions_file2canvas_form',
'summary theme' => 'canvasactions_file2canvas_summary',
);
$effects['canvasactions_canvas2file'] = array(
'label' => t('Underlay (background)'),
'help' => t('Choose the file image you wish to use as an background, and position the processed image on it.'),
'effect callback' => 'canvasactions_canvas2file_image',
'dimensions callback' => 'canvasactions_canvas2file_dimensions',
'form callback' => 'canvasactions_canvas2file_form',
'summary theme' => 'canvasactions_canvas2file_summary',
);
$effects['canvasactions_source2canvas'] = array(
'label' => t('Overlay: source image to canvas'),
'help' => t('Places the source image onto the canvas for compositing.'),
'effect callback' => 'canvasactions_source2canvas_image',
'dimensions passthrough' => TRUE,
'form callback' => 'canvasactions_source2canvas_form',
'summary theme' => 'canvasactions_source2canvas_summary',
);
$effects['canvasactions_roundedcorners'] = array(
'label' => t('Rounded Corners'),
'help' => t('This is true cropping, not overlays, so the result <em>can</em> be transparent.'),
'effect callback' => 'canvasactions_roundedcorners_image',
'dimensions passthrough' => TRUE,
'form callback' => 'canvasactions_roundedcorners_form',
'summary theme' => 'canvasactions_roundedcorners_summary',
);
$effects['canvasactions_aspect'] = array(
'label' => t('Aspect switcher'),
'help' => t('Use different effects depending on whether the image is landscape of portrait shaped. This re-uses other preset definitions, and just chooses between them based on the rule.'),
'effect callback' => 'canvasactions_aspect_image',
'dimensions callback' => 'canvasactions_aspect_dimensions',
'form callback' => 'canvasactions_aspect_form',
'summary theme' => 'canvasactions_aspect_summary',
);
return $effects;
}
/**
* Need to register the theme functions we expect to use
*/
function imagecache_canvasactions_theme() {
$util_dir = drupal_get_path('module', 'imagecache_actions');
return array(
'canvasactions_definecanvas_summary' => array(
'file' => 'canvasactions.inc',
'variables' => array('data' => NULL),
),
'canvasactions_imagemask_summary' => array(
'file' => 'canvasactions.inc',
'arguments' => array('element' => NULL),
),
'canvasactions_file2canvas_summary' => array(
'file' => 'canvasactions.inc',
'variables' => array('data' => NULL),
),
'canvasactions_source2canvas_summary' => array(
'file' => 'canvasactions.inc',
'variables' => array('data' => NULL),
),
'canvasactions_canvas2file_summary' => array(
'file' => 'canvasactions.inc',
'variables' => array('data' => NULL),
),
'canvasactions_roundedcorners_summary' => array(
'file' => 'rounded_corners.inc',
'variables' => array('data' => NULL),
),
'canvasactions_aspect_summary' => array(
'file' => 'canvasactions.inc',
'variables' => array('data' => NULL),
),
);
}
/**
* Implements hook_image_style_flush.
*
* This hook checks if the image style that is being flushed is used in an
* aspect switcher effect. If so, the style that contains the aspect switcher
* effect, should be flushed as well as the flushed style was probably changed.
*
* @param array $flushed_style
* The image style that is being flushed.
*/
function imagecache_canvasactions_image_style_flush($flushed_style) {
$styles = image_styles();
foreach ($styles as $style) {
if ($style['name'] !== $flushed_style['name']) {
foreach ($style['effects'] as $effect) {
if ($effect['name'] === 'canvasactions_aspect') {
if ( (isset($effect['data']['portrait']) && $effect['data']['portrait'] === $flushed_style['name'])
|| (isset($effect['data']['landscape']) && $effect['data']['landscape'] === $flushed_style['name'])) {
image_style_flush($style);
}
}
}
}
}
}

View File

@@ -0,0 +1,325 @@
<?php
/**
* @file Routines for rounded corners
*/
/**
* Set radius for corner rounding
*
* Implementation of imagecache_hook_form()
*
* @param $action array of settings for this action
* @return a form definition
*/
function canvasactions_roundedcorners_form($action) {
if (image_get_toolkit() != 'gd') {
drupal_set_message('Rounded corners are not currently supported on all versions of imagemagick. This effect works best with GD image toolkit only.', 'warning');
}
drupal_add_js(drupal_get_path('module', 'imagecache_actions') . '/imagecache_actions.jquery.js');
$defaults = array(
'radius' => '16',
#'antialias' => TRUE,
'independent_corners_set' => array(
'independent_corners' => FALSE,
'radii' => array(
'tl' => 0,
'tr' => 0,
'bl' => 0,
'br' => 0,
),
),
);
$action = array_merge($defaults, (array) $action);
$form['radius'] = array(
'#type' => 'textfield',
'#title' => t('radius'),
'#default_value' => $action['radius'],
'#size' => 2,
);
$form['independent_corners_set'] = array(
'#type' => 'fieldset',
'#title' => t('Individual Corner Values'),
'#collapsible' => TRUE,
'#collapsed' => (! $action['independent_corners_set']['independent_corners']),
);
$form['independent_corners_set']['independent_corners'] = array(
'#type' => 'checkbox',
'#title' => t('Set Corners Independently'),
'#default_value' => $action['independent_corners_set']['independent_corners'],
);
$corners = array(
'tl' => t("Top Left Radius"),
'tr' => t("Top Right Radius"),
'bl' => t("Bottom Left Radius"),
'br' => t("Bottom Right Radius"),
);
// Loop over the four corners and create field elements for them.
$form['independent_corners_set']['radii'] = array(
'#type' => 'item',
'#id' => 'independent-corners-set',
);
foreach ($corners as $attribute => $label) {
$form['independent_corners_set']['radii'][$attribute] = array(
'#type' => 'textfield',
'#title' => $label,
'#default_value' => 0 + $action['independent_corners_set']['radii'][$attribute],
'#size' => 2,
);
}
/*
$form['antialias'] = array(
'#type' => 'checkbox',
'#title' => t('antialias'),
'#return_value' => TRUE,
'#default_value' => $action['antialias'],
'#description' => t('Attempt antialias smoothing when drawing the corners'),
);
*/
$form['notes'] = array(
'#type' => 'markup',
'#value' => t('
Note: the rounded corners effect uses true alpha transparency masking.
This means that this effect <b>will fail to be saved</b> on jpegs
<em>unless</em> you either <ul>
<li>convert the image to PNG (using the coloractions filter for that),</li>
<li>define a canvas underneath it (using canvasactions-define-canvas) or</li>
<li>underlay a solid color (using coloractions-alpha-flatten) or</li>
<li>underlay a background image (canvasactions-underlay)</li>
</ul>
as a later part of this imagecache pipeline.
<br/>
'),
);
return $form;
}
function canvasactions_roundedcorners_image($image, $action = array()) {
$independent_corners = !empty($action['independent_corners_set']['independent_corners']);
if (!$independent_corners) {
// set the independant corners to all be the same.
$corners = array('tl', 'tr', 'bl', 'br');
foreach ($corners as $key) {
// Use the all-the-same radius setting.
$action['independent_corners_set']['radii'][$key] = $action['radius'];
}
}
return image_toolkit_invoke('roundedcorners', $image, array($action));
}
/**
* Trim rounded corners off an image, using an anti-aliasing algorithm.
*
* Implementation of hook_image()
*
* Note, this is not image toolkit-agnostic yet! It just assumes GD.
* We can abstract it out once we have something else to abstract to.
* In the meantime just don't.
*
* 'handcoded' rounded corners logic contributed by donquixote 2009-08-31
*
* @param $image
* @param $action
*/
function image_gd_roundedcorners($image, $action = array()) {
// Read settings.
$width = $image->info['width'];
$height = $image->info['height'];
$radius = $action['radius'];
$independent_corners = !empty($action['independent_corners_set']['independent_corners']);
$corners = array('tl', 'tr', 'bl', 'br');
$im = &$image->resource;
// Prepare drawing on the alpha channel.
imagesavealpha($im, TRUE);
imagealphablending($im, FALSE);
foreach ($corners as $key) {
if ($independent_corners && isset($action['independent_corners_set']['radii'][$key])) {
$r = $action['independent_corners_set']['radii'][$key];
}
else {
// Use the all-the-same radius setting.
$r = $radius;
}
// key can be 'tl', 'tr', 'bl', 'br'.
$is_bottom = ($key{0} == 'b');
$is_right = ($key{1} == 'r');
// dx and dy are in "continuous coordinates",
// and mark the distance of the pixel middle to the image border.
for ($dx = .5; $dx < $r; ++$dx) {
for ($dy = .5; $dy < $r; ++$dy) {
// ix and iy are in discrete pixel indices,
// counting from the top left
$ix = floor($is_right ? $width -$dx : $dx);
$iy = floor($is_bottom ? $height -$dy : $dy);
// Color lookup at ($ix, $iy).
$color_ix = imagecolorat($im, $ix, $iy);
$color = imagecolorsforindex($im, $color_ix);
// Do not process opacity if transparency is 100%. Just jump...
// Opacity is always 0 on a transparent source pixel.
if ($color['alpha'] != 127) {
$opacity = _canvasactions_roundedcorners_pixel_opacity($dx, $dy, $r);
if ($opacity >= 1) {
// we can finish this row,
// all following pixels will be fully opaque.
break;
}
if (isset($color['alpha'])) {
$color['alpha'] = 127 - round($opacity * (127 - $color['alpha']));
}
else {
$color['alpha'] = 127 - round($opacity * 127);
}
// Value should not be more than 127, and not less than 0.
$color['alpha'] = ($color['alpha'] > 127) ? 127 : (($color['alpha'] < 0) ? 0 : $color['alpha']);
}
$color_ix = imagecolorallocatealpha($im, $color['red'], $color['green'], $color['blue'], $color['alpha']);
imagesetpixel($im, $ix, $iy, $color_ix);
}
}
}
return TRUE;
}
/**
* Calculate the transparency value for a rounded corner pixel
*
* @param $x
* distance from pixel center to image border (left or right)
* should be an integer + 0.5
*
* @param $y
* distance from pixel center to image border (top or bottom)
* should be an integer + 0.5
*
* @param $r
* radius of the rounded corner
* should be an integer
*
* @return float
* opacity value between 0 (fully transparent) and 1 (fully opaque).
*
* OPTIMIZE HERE! This is a really tight loop, potentially getting called
* thousands of times
*/
function _canvasactions_roundedcorners_pixel_opacity($x, $y, $r) {
if ($x < 0 || $y < 0) {
return 0;
}
else if ($x > $r || $y > $r) {
return 1;
}
$dist_2 = ($r -$x) * ($r -$x) + ($r -$y) * ($r -$y);
$r_2 = $r * $r;
if ($dist_2 > ($r + 0.8) * ($r + 0.8)) {
return 0;
}
else if ($dist_2 < ($r -0.8) * ($r -0.8)) {
return 1;
}
else {
// this pixel needs special analysis.
// thanks to a quite efficient algorithm, we can afford 10x antialiasing :)
$opacity = 0.5;
if ($x > $y) {
// cut the pixel into 10 vertical "stripes"
for ($dx = -0.45; $dx < 0.5; $dx += 0.1) {
// find out where the rounded corner edge intersects with the stripe
// this is plain triangle geometry.
$dy = $r - $y - sqrt($r_2 - ($r -$x -$dx) * ($r -$x -$dx));
$dy = ($dy > 0.5) ? 0.5 : (($dy < -0.5) ? -0.5 : $dy);
// count the opaque part of the stripe.
$opacity -= 0.1 * $dy;
}
}
else {
// cut the pixel into 10 horizontal "stripes"
for ($dy = -0.45; $dy < 0.5; $dy += 0.1) {
// this is the math:
// ($r-$x-$dx)^2 + ($r-$y-$dy)^2 = $r^2
// $dx = $r - $x - sqrt($r^2 - ($r-$y-$dy)^2)
$dx = $r - $x - sqrt($r_2 - ($r -$y -$dy) * ($r -$y -$dy));
$dx = ($dx > 0.5) ? 0.5 : (($dx < -0.5) ? -0.5 : $dx);
$opacity -= 0.1 * $dx;
}
}
return ($opacity < 0) ? 0 : (($opacity > 1) ? 1 : $opacity);
}
}
/**
* imageapi_roundedcorners
*/
function image_imagemagick_roundedcorners($image, $action = array()) {
// Based on the imagemagick documentation.
// http://www.imagemagick.org/Usage/thumbnails/#rounded
// Create arc cut-outs, then mask them.
// Draw black triangles and white circles.
// draw circle is center: x,y, and a point on the perimeter
$corners = array('tl', 'tr', 'bl', 'br');
$radii = $action['independent_corners_set']['radii'];
$width = $image->info['width'];
$height = $image->info['height'];
$tl = $radii['tl'];
$tr = $radii['tr'];
$bl = $radii['bl'];
$br = $radii['br'];
$drawmask = '';
if ($tl) {
$drawmask .= " fill black polygon 0,0 0,{$tl} {$tl},0";
$drawmask .= " fill white circle {$tl},{$tl} {$tl},0";
}
if ($tr) {
$right = $width -$tr;
$drawmask .= " fill black polygon {$right},0 {$width},0 {$width},{$tr}";
$drawmask .= " fill white circle {$right},{$tr} {$right},0";
}
if ($bl) {
$bottom = $height -$bl;
$drawmask .= " fill black polygon 0,{$bottom} 0,{$height} {$bl},{$height}";
$drawmask .= " fill white circle {$bl},{$bottom} 0,{$bottom}";
}
if ($br) {
$bottom = $height -$br;
$right = $width -$br;
$drawmask .= " fill black polygon {$right},{$height} {$width},{$bottom} {$width},{$height}";
$drawmask .= " fill white circle {$right},{$bottom} {$width},{$bottom}";
}
$draw = ' -draw ' . escapeshellarg($drawmask);
$compose = ' ' . escapeshellcmd('(') . " +clone -threshold -1 $draw " . escapeshellcmd(')') . ' +matte -compose CopyOpacity -composite ';
$image->ops[] = $compose;
return TRUE;
}
/**
* Implementation of theme_hook() for imagecache_ui.module
*/
function theme_canvasactions_roundedcorners($variables) {
$element = $variables['element'];
$data = $element['#value'];
if (!empty($data['independent_corners_set']['independent_corners'])) {
$dimens = join('px | ', $data['independent_corners_set']['radii']) . 'px';
}
else {
$dimens = "Radius: {$data['radius']}px";
}
return $dimens;
}

View File

@@ -0,0 +1,114 @@
<?php
// $ID: $
/**
* @file
* Test imagecache preset.
*
* Created on Dec 29, 2009
*
* @author 'dman' Dan Morrison http://coders.co.nz/
*/
$presets['cheap_dropshadow'] = array (
'name' => 'cheap_dropshadow',
'#weight' => '3.3',
'effects' =>
array (
-1 => array (
'weight' => '-1',
'module' => 'imagecache_coloractions',
'name' => 'coloractions_convert',
'data' => array (
'format' => 'image/png',
),
),
0 =>
array (
'weight' => '0',
'module' => 'imagecache_canvasactions',
'name' => 'canvasactions_definecanvas',
'data' =>
array (
'RGB' =>
array (
'HEX' => '999999',
),
'under' => 0,
'exact' =>
array (
'width' => '',
'height' => '',
'xpos' => 'center',
'ypos' => 'center',
),
'relative' =>
array (
'leftdiff' => '0',
'rightdiff' => '0',
'topdiff' => '0',
'bottomdiff' => '0',
),
),
),
1 =>
array (
'weight' => '1',
'module' => 'imagecache_canvasactions',
'name' => 'canvasactions_definecanvas',
'data' =>
array (
'RGB' =>
array (
'HEX' => '',
),
'under' => 1,
'exact' =>
array (
'width' => '',
'height' => '',
'xpos' => 'center',
'ypos' => 'center',
),
'relative' =>
array (
'leftdiff' => '20',
'rightdiff' => '0',
'topdiff' => '20',
'bottomdiff' => '0',
),
),
),
2 =>
array (
'weight' => '2',
'module' => 'imagecache_canvasactions',
'name' => 'canvasactions_source2canvas',
'data' =>
array (
'xpos' => 0,
'ypos' => 0,
'alpha' => '100',
),
),
3 =>
array (
'weight' => '3',
'module' => 'image',
'name' => 'image_scale',
'data' =>
array (
'width' => '200',
'height' => '100%',
'upscale' => 0,
),
),
4 => array (
'weight' => '10',
'module' => 'imagecache_coloractions',
'name' => 'coloractions_convert',
'data' => array (
'format' => 'image/png',
),
),
),
);

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View File

@@ -0,0 +1,62 @@
<?php
// $ID: $
/**
* @file
* Test imagecache preset.
*
* Created on Dec 29, 2009
*
* @author 'dman' Dan Morrison http://coders.co.nz/
*/
$presets['keyword_positioning'] = array (
'name' => 'keyword_positioning',
'#weight' => 4.2,
'effects' => array (
array (
'weight' => '-1',
'module' => 'imagecache_canvasactions',
'name' => 'canvasactions_file2canvas',
'data' => array (
'xpos' => 'right',
'ypos' => 'top',
'alpha' => '100',
'path' => drupal_get_path('module', 'imagecache_testsuite') . "/grid-240x160.png",
),
),
array (
'weight' => '0',
'module' => 'imagecache_canvasactions',
'name' => 'canvasactions_file2canvas',
'data' => array (
'xpos' => '25%',
'ypos' => 'bottom-10%',
'path' => 'misc/druplicon.png',
),
),
array (
'weight' => '0',
'module' => 'imagecache_canvasactions',
'name' => 'canvasactions_file2canvas',
'data' => array (
'xpos' => '0%',
'ypos' => 'top+10%',
'path' => 'misc/druplicon.png',
),
),
array (
'weight' => '0',
'module' => 'imagecache_canvasactions',
'name' => 'canvasactions_file2canvas',
'data' => array (
'xpos' => 'right+50',
'ypos' => '50%',
'path' => 'misc/druplicon.png',
),
),
),
);

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

View File

@@ -0,0 +1,47 @@
<?php
// $ID: $
/**
* @file
* Test imagecache preset.
*
* Created on Dec 29, 2009
*
* @author 'dman' Dan Morrison http://coders.co.nz/
*/
$presets['positioned_underlay'] = array (
'name' => 'positioned_underlay',
'#weight' => 4.4,
'effects' => array (
0 => array (
'module' => 'image',
'name' => 'image_scale',
'weight' => '0',
'data' => array (
'width' => '200',
'height' => '',
'upscale' => 0,
),
),
1 => array (
'module' => 'imagecache_canvasactions',
'name' => 'canvasactions_canvas2file',
'weight' => '1',
'data' => array (
'xpos' => '50',
'ypos' => 'bottom+50',
'alpha' => '100',
'path' => "$filepath/shiny-bg.png",
'dimensions' => 'background',
),
),
4 => array (
'weight' => '10',
'module' => 'imagecache_coloractions',
'name' => 'coloractions_convert',
'data' => array (
'format' => 'image/png',
),
),
),
);

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

View File

@@ -0,0 +1,35 @@
<?php
// $ID: $
/**
* @file
* Test imagecache preset.
*
* Created on Dec 29, 2009
*
* @author 'dman' Dan Morrison http://coders.co.nz/
*/
$presets['rotate_alpha'] = array (
'name' => 'rotate_alpha',
'#weight' => 1.4,
'effects' => array (
1 => array (
'weight' => '1',
'module' => 'image',
'name' => 'image_rotate',
'data' => array (
'degrees' => '15',
'random' => 0,
'bgcolor' => '',
),
),
3 => array (
'weight' => '3',
'module' => 'imagecache_coloractions',
'name' => 'coloractions_convert',
'data' => array (
'format' => 'image/png',
),
),
),
);

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

View File

@@ -0,0 +1,36 @@
<?php
// $ID: $
/**
* @file
* Test imagecache preset.
*
* Created on Dec 29, 2009
*
* @author 'dman' Dan Morrison http://coders.co.nz/
*/
$presets['rotate_alpha_gif'] = array (
'name' => 'rotate_alpha_gif',
'#weight' => 1.5,
'effects' => array (
1 => array (
'weight' => '1',
'module' => 'image',
'name' => 'image_rotate',
'data' => array (
'degrees' => '15',
'random' => 0,
'bgcolor' => '',
),
),
3 => array (
'weight' => '3',
'module' => 'imagecache_coloractions',
'name' => 'coloractions_convert',
'data' => array (
'format' => 'image/gif',
),
),
),
);

View File

@@ -0,0 +1,38 @@
<?php
// $ID: $
/**
* @file
* Test imagecache preset.
*
* Created on Dec 29, 2009
*
* @author 'dman' Dan Morrison http://coders.co.nz/
*/
$presets['rotate_scale'] = array (
'name' => 'rotate_scale',
'#weight' => 1.2,
'effects' => array (
1 => array (
'weight' => '1',
'module' => 'image',
'name' => 'image_rotate',
'data' => array (
'degrees' => '15',
'random' => 0,
'bgcolor' => '',
),
),
2 => array (
'weight' => '2',
'module' => 'image',
'name' => 'image_scale',
'data' => array (
'width' => '',
'height' => '150',
'upscale' => TRUE,
),
),
),
);

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

View File

@@ -0,0 +1,59 @@
<?php
// $ID: $
/**
* @file
* Test imagecache preset.
*
* Created on Dec 29, 2009
*
* @author 'dman' Dan Morrison http://coders.co.nz/
*/
$presets['rotate_scale_alpha'] = array (
'name' => 'rotate_scale_alpha',
'#weight' => 1.6,
'effects' => array (
1 => array (
'weight' => '1',
'module' => 'image',
'name' => 'image_rotate',
'data' => array (
'degrees' => '65',
'random' => 0,
'bgcolor' => '',
),
),
/*
* imageapi resize is NOT alpha-safe. This test case proves the bug.
* A work-around is to change format before resizing.
2 => array (
'weight' => '2',
'module' => 'imagecache_coloractions',
'name' => 'coloractions_convert',
'data' => array (
'format' => 'image/png',
),
),
*/
3 => array (
'weight' => '3',
'module' => 'image',
'name' => 'image_scale',
'data' => array (
'width' => '',
'height' => '150',
'upscale' => TRUE,
),
),
4 => array (
'weight' => '4',
'module' => 'imagecache_coloractions',
'name' => 'coloractions_convert',
'data' => array (
'format' => 'image/png',
),
),
),
);

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

View File

@@ -0,0 +1,34 @@
<?php
// $ID: $
/**
* @file
* Test imagecache preset.
*
* Created on Dec 29, 2009
*
* @author 'dman' Dan Morrison http://coders.co.nz/
*/
$presets['rounded'] = array (
'name' => 'rounded',
'#weight' => 3.0,
'effects' => array (
1 => array (
'weight' => '0',
'module' => 'imagecache_canvasactions',
'name' => 'canvasactions_roundedcorners',
'data' => array (
'radius' => '25',
'antialias' => true,
),
),
2 => array (
'weight' => '3',
'module' => 'imagecache_coloractions',
'name' => 'coloractions_convert',
'data' =>array (
'format' => 'image/png',
),
),
),
);

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

View File

@@ -0,0 +1,43 @@
<?php
// $ID: $
/**
* @file
* Test imagecache preset.
*
* Created on Dec 29, 2009
*
* @author 'dman' Dan Morrison http://coders.co.nz/
*/
$presets['rounded_bl'] = array (
'name' => 'rounded_bl',
'#weight' => 3.1,
'effects' => array (
1 => array (
'weight' => '0',
'module' => 'imagecache_canvasactions',
'name' => 'canvasactions_roundedcorners',
'data' => array (
'radius' => '50',
'independent_corners_set' => array (
'independent_corners' => 1,
'radii' => array (
'tl' => '10',
'tr' => '0',
'bl' => '50',
'br' => '10',
),
),
'antialias' => true,
),
),
2 => array (
'weight' => '3',
'module' => 'imagecache_coloractions',
'name' => 'coloractions_convert',
'data' =>array (
'format' => 'image/png',
),
),
),
);

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

View File

@@ -0,0 +1,59 @@
<?php
// $ID: $
/**
* @file
* Test imagecache preset.
*
* Created on Dec 29, 2009
*
* @author 'dman' Dan Morrison http://coders.co.nz/
*/
$presets['rounded_flattened'] = array (
'name' => 'rounded_flattened',
'#weight' => 3.3,
'effects' => array (
1 => array (
'weight' => '0',
'module' => 'imagecache_canvasactions',
'name' => 'canvasactions_roundedcorners',
'data' => array (
'radius' => '50',
'independent_corners_set' => array (
'independent_corners' => 1,
'radii' => array (
'tr' => '100',
'br' => '0',
'tl' => '0',
'bl' => '0',
),
),
'antialias' => true,
),
),
2 => array (
'weight' => '0',
'module' => 'imagecache_canvasactions',
'name' => 'canvasactions_definecanvas',
'data' => array (
'RGB' => array (
'HEX' => '333333',
),
'under' => 1,
'exact' => array (
'width' => '',
'height' => '',
'xpos' => 'center',
'ypos' => 'center',
),
'relative' => array (
'leftdiff' => '2',
'rightdiff' => '2',
'topdiff' => '2',
'bottomdiff' => '2',
),
),
),
),
);

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@@ -0,0 +1,28 @@
<?php
// $ID: $
/**
* @file
* Test imagecache preset.
*
* Created on Dec 29, 2009
*
* @author 'dman' Dan Morrison http://coders.co.nz/
*/
$presets['watermark_100'] = array (
'name' => 'watermark_100',
'#weight' => 4.0,
'effects' => array (
0 => array (
'weight' => '0',
'module' => 'imagecache_canvasactions',
'name' => 'canvasactions_file2canvas',
'data' => array (
'xpos' => '10',
'ypos' => '5',
'alpha' => '100',
'path' => 'misc/druplicon.png',
),
),
),
);

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

View File

@@ -0,0 +1,28 @@
<?php
// $ID: $
/**
* @file
* Test imagecache preset.
*
* Created on Dec 29, 2009
*
* @author 'dman' Dan Morrison http://coders.co.nz/
*/
$presets['watermark_50'] = array (
'name' => 'watermark_50',
'#weight' => 4.1,
'effects' => array (
0 => array (
'weight' => '0',
'module' => 'imagecache_canvasactions',
'name' => 'canvasactions_file2canvas',
'data' => array (
'xpos' => 'right+20',
'ypos' => 'bottom',
'alpha' => '50',
'path' => 'misc/druplicon.png',
),
),
),
);

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB