function textactions_rendertext_image in ImageCache Actions 6
Place the text defined in the action onto the current background
Implementation of hook_image()
Parameters
$image:
$action:
File
- ./
textrender.inc, line 103 - Helper functions for imagecache_textactions
Code
function textactions_rendertext_image(&$image, $action = array()) {
if (!empty($action['evaluate_text'])) {
$text = textactions_evaluate_text($image, $action);
}
else {
$text = $action['text'];
}
if (empty($text)) {
// Do nothing, carry on
return TRUE;
}
$style = imageapi_text_parse_style($action['textstyle']['style']);
$fontfile = $action['textstyle']['fontfile'];
// Calculate position by first creating a temp image
// containing the text and then accessing its dimensions.
// Inefficient, but reliable.
// $textimage is a placeholder that will get the image created in it - an object to work like the rest of the imageapi functions.
// We really need to force the toolkit to GD, but even then it can't be merged back into imagemagick
$textimage = (object) array(
'toolkit' => $image->toolkit,
);
if (!imageapi_image_create_text($textimage, $text, $fontfile, $style) || empty($textimage->info)) {
drupal_set_message(t('Failed to generate text image using %toolkit. Not overlaying text.', array(
'%toolkit' => $textimage->toolkit,
)), 'error');
return FALSE;
}
// $textimage should now have its size info available.
// Calc the position on the canvas
$xy = imagecache_actions_calculate_relative_position($image, $textimage, $style);
#dpm(get_defined_vars());
return imageapi_image_overlay($image, $textimage, $xy['x'], $xy['y']);
}