View source
<?php
function textimage_requirements($phase) {
$t = get_t();
$requirements['textimage_gd'] = array(
'title' => $t('GD library'),
);
if (function_exists('imagegd2')) {
$info = gd_info();
$requirements['textimage_gd']['value'] = $info['GD Version'];
if (function_exists('imagettftext') && $info["FreeType Support"]) {
if (!module_exists('color') && !module_exists('imageapi_gd')) {
$requirements['textimage_gd']['severity'] = REQUIREMENT_OK;
}
else {
$requirements = array();
}
}
else {
$requirements['textimage_gd']['severity'] = REQUIREMENT_ERROR;
$requirements['textimage_gd']['description'] = $t('The GD library for PHP is enabled, but was compiled without FreeType support. Please check the <a href="@url">PHP image documentation</a> for information on how to correct this.', array(
'@url' => 'http://www.php.net/manual/en/ref.image.php',
));
}
}
else {
$requirements['textimage_gd'] = array(
'value' => $t('Not installed'),
'severity' => REQUIREMENT_ERROR,
'description' => $t('The GD library for PHP is missing or outdated. Please check the <a href="@url">PHP image documentation</a> for information on how to correct this.', array(
'@url' => 'http://www.php.net/manual/en/image.setup.php',
)),
);
}
return $requirements;
}
function textimage_schema() {
$schema['textimage_preset'] = array(
'fields' => array(
'pid' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'name' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'description' => array(
'type' => 'text',
'size' => 'medium',
'not null' => TRUE,
),
'settings' => array(
'type' => 'text',
'not null' => TRUE,
),
),
'primary key' => array(
'pid',
),
);
$schema['textimage_image'] = array(
'fields' => array(
'pid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'file' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'data' => array(
'type' => 'text',
'not null' => TRUE,
),
),
'primary key' => array(
'file',
),
);
return $schema;
}
function textimage_install() {
drupal_install_schema('textimage');
}
function textimage_uninstall() {
include_once drupal_get_path('module', 'textimage') . '/textimage_admin.inc';
drupal_uninstall_schema('textimage');
$path = realpath(file_directory_path() . '/textimage');
if ($path != FALSE) {
_textimage_recursive_delete($path);
}
db_query("DELETE from {variable} WHERE name LIKE '%%textimage_%%'");
}
function textimage_update_1() {
$ret = array();
$schema['textimage_preset'] = array(
'fields' => array(
'pid' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'name' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'settings' => array(
'type' => 'text',
'not null' => TRUE,
),
),
'primary key' => array(
'pid',
),
);
db_create_table($ret, 'textimage_preset', $schema['textimage_preset']);
return $ret;
}
function textimage_update_2() {
$ret = array();
$schema['textimage_image'] = array(
'fields' => array(
'pid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'file' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'data' => array(
'type' => 'text',
'not null' => TRUE,
),
),
'primary key' => array(
'file',
),
);
db_create_table($ret, 'textimage_image', $schema['textimage_image']);
include_once drupal_get_path('module', 'textimage') . '/textimage_admin.inc';
foreach (textimage_get_presets() as $preset) {
$path = realpath(file_directory_path() . '/textimage/' . $preset->name);
if (is_dir($path)) {
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
foreach ($files as $file => $object) {
$file = str_replace($path . '/', '', $file);
$args = explode('/', $file);
$filename = urldecode(array_pop($args));
$additional_text = $args;
preg_match('/\\.([a-z]+)$/i', $filename, $matches);
$format = $matches[1];
if ($format == 'jpg') {
$format = 'jpeg';
}
$text = preg_replace('/\\.([a-z]+)$/i', '', $filename);
db_query("INSERT {textimage_image} (pid, file, data) VALUES (%d, '%s', '%s')", $preset['pid'], file_directory_path() . '/textimage/' . $preset->name . '/' . $file, serialize(array(
'format' => $format,
'text' => $text,
'additional_text' => $additional_text,
)));
}
}
}
return $ret;
}
function textimage_update_3() {
$ret = array();
include_once drupal_get_path('module', 'textimage') . '/textimage_admin.inc';
$presets = textimage_get_presets();
foreach ($presets as $preset) {
if ($preset->settings['text']['angle'] != 0) {
$preset->settings['text']['angle'] = -$preset->settings['text']['angle'];
_textimage_preset_update($preset->pid, $preset->name, $preset->description, $preset->settings);
}
}
return $ret;
}
function textimage_update_4() {
$ret = array();
db_add_field($ret = array(), 'textimage_preset', 'description', array(
'type' => 'text',
'size' => 'medium',
'not null' => TRUE,
));
include_once drupal_get_path('module', 'textimage') . '/textimage_admin.inc';
$presets = textimage_get_presets();
foreach ($presets as $preset) {
if (!isset($preset->settings['font'])) {
$preset->settings['font'] = array(
'file' => $preset->settings['text']['font'],
'size' => $preset->settings['text']['size'],
'color' => array(
'hex' => $preset->settings['text']['color'],
'opacity' => 100,
),
);
unset($preset->settings['text']['font']);
unset($preset->settings['text']['size']);
unset($preset->settings['text']['color']);
}
if (!isset($preset->settings['text']['margin'])) {
$preset->settings['text']['margin'] = array(
'top' => $preset->settings['text']['margin_top'],
'right' => $preset->settings['text']['margin_right'],
'bottom' => $preset->settings['text']['margin_bottom'],
'left' => $preset->settings['text']['margin_left'],
);
unset($preset->settings['text']['margin_top']);
unset($preset->settings['text']['margin_right']);
unset($preset->settings['text']['margin_bottom']);
unset($preset->settings['text']['margin_left']);
}
if (!isset($preset->settings['text']['stroke'])) {
$preset->settings['text']['stroke'] = array(
'width' => $preset->settings['text']['stroke_width'],
'color' => $preset->settings['text']['stroke_color'],
);
unset($preset->settings['text']['stroke_width']);
unset($preset->settings['text']['stroke_color']);
}
if (!isset($preset->settings['preview']['text']['default'])) {
$preset->settings['preview']['text']['default'] = $preset->settings['preview']['text'];
unset($preset->settings['preview']['text']);
}
if (isset($preset->settings['description'])) {
$preset->description = $preset->settings['description'];
unset($preset->settings['description']);
}
_textimage_preset_update($preset->pid, $preset->name, $preset->description, $preset->settings);
}
return $ret;
}