View source
<?php
require_once dirname(__FILE__) . '/utility.inc';
function imagecache_textactions_imagecache_actions() {
$actions = array(
'textactions_text2canvas' => array(
'name' => t('Text'),
'description' => t('Add static or dynamic (coded) text to an image.'),
'file' => 'textactions.inc',
),
'textactions_rendertext' => array(
'name' => t('Render Text'),
'description' => t('EXPERIMENTAL Add static or dynamic (coded) text to an image using <a href="!imageapi_link">imageapi_text</a> CSS-like effects.', array(
url('admin/settings/imageapi/config/text'),
)),
'file' => 'textrender.inc',
),
);
return $actions;
}
function imagecache_textactions_help($path, $arg) {
switch ($path) {
case 'admin/help#imagecache_textactions':
$output = "<p>\n For text rendering to work on a server, we <em>must</em>\n know the system path to the font <em>file</em>, not just the name.\n Font library handling differs too much on different systems and\n the available PHP toolkits are unable to return good diagnostics.\n </p><p>\n On Debian/Ubuntu, you may find your fonts in and under\n <code>/usr/share/fonts/truetype/</code>\n eg <code>'/usr/share/fonts/truetype/ttf-bitstream-vera/VeraMono.ttf'</code>\n </p><p>\n On OSX, they are probably in <code>/Library/Fonts/</code>\n eg <code>'/Library/Fonts/Times New Roman Bold Italic.ttf'</code>\n </p><p>\n On Windows, they are probably in <code>C://WINDOWS/Fonts/</code>\n eg <code>'C://WINDOWS/Fonts/comic.TTF'</code>\n </p><p>\n Of course, this will change if you deploy to a different server!\n so the best approach is to place your own TTF font file inside your\n <em>files</em> directory and use that. \n Just give the filename with no path and it should be found..\n </p>\n ";
$output .= t("<p>Files directory is !files</p>", array(
'!files' => file_directory_path(),
));
if (ini_get('safe_mode')) {
$output .= t("<p>\n It appears PHP 'safe mode' is on. \n This prevents me for knowing which fonts are on your system. \n You will have to know the exact path and filename of the fonts you intend to use \n - or upload some *.ttf files to your 'files' directory and use them from there.\n </p>");
}
else {
$list = `find /usr/share/fonts -name \\*.ttf`;
$output .= "<p>Fonts Found : <pre>" . $list . "</pre></p>";
}
return $output;
break;
}
}
function imagecache_textactions_theme() {
return array(
'textactions_text2canvas' => array(
'file' => 'textactions.inc',
'arguments' => array(
'element' => NULL,
),
),
'textactions_rendertext' => array(
'file' => 'textrender.inc',
'arguments' => array(
'element' => NULL,
),
),
'imagecacheactions_rgb_form' => array(
'file' => 'utility.inc',
'arguments' => array(
'form' => NULL,
),
),
'imagecacheactions_rgb' => array(
'file' => 'utility.inc',
'arguments' => array(
'rgb' => NULL,
),
),
);
}
function textactions_evaluate_text($image, $action) {
if (!empty($image->source)) {
$meta = module_invoke_all('metadata_from_file', $image->source);
$file_data = (object) $meta;
}
static $panic;
if ($panic) {
return;
}
$panic = TRUE;
$node = imagecache_actions_node_from_filepath($image->source, $file_data);
$panic = FALSE;
$GLOBALS['image'] = $image;
$GLOBALS['node'] = $node;
$GLOBALS['file_data'] = $file_data;
$text = @drupal_eval('<' . '?php global $node; global $image; global $file_data; ' . $action['text'] . ' ?' . '>');
if (empty($text) && function_exists('error_get_last') && ($last_error = error_get_last())) {
drupal_set_message("Problem evaluating dynamic text. <br/><code>{$action['text']}</code><br/> " . $last_error['message'], 'error');
}
return $text;
}