You are here

function textimage_image in Textimage 6.2

Same name and namespace in other branches
  1. 5.2 textimage.module \textimage_image()
  2. 5 textimage.module \textimage_image()
  3. 7.2 textimage.module \textimage_image()

Menu Callback function converts the current textimage path into an image. On first request, the image is returned to the browser from Drupal and then saved to the disk. On subsequent requests (with Clean URLs enabled), the cached image is loaded directly.

This function takes a dynamic number of arguments.

Parameters

$preset_name: The name of the preset to be used in this textimage

...: An unlimited number of additional text parameters to be used as the display text for textimages displayed on top of one another. Only used if the current preset has the its Background Image option set to the result of another preset. Text is used in reverse order. So the last directory will be the first chained preset used.

$text: The text to be displayed in this preset with the output format appended as the file extension. For example, 'sample.png' will output a PNG with the text 'sample'. 'sample.jpg' will output the same image but in JPG format.

2 string references to 'textimage_image'
textimage_menu in ./textimage.module
Implementation of hook_menu().
textimage_update_2 in ./textimage.install

File

./textimage.module, line 259

Code

function textimage_image() {
  $pattern = '/' . str_replace('/', '\\/', base_path() . '(\\?q=)?' . file_directory_path() . '/textimage/') . '/';
  $args = explode('/', preg_replace($pattern, '', request_uri()));
  $preset = array_shift($args);
  if (is_numeric($preset)) {
    drupal_not_found();
    exit;
  }
  $filename = urldecode(array_pop($args));
  $additional_text = $args;

  // Determine our output format
  preg_match('/\\.([a-z]+)$/i', $filename, $matches);
  $format = $matches[1];
  if ($format == 'jpg') {
    $format = 'jpeg';
  }

  // Determine the text to display
  $text = preg_replace('/\\.([a-z]+)$/i', '', $filename);
  if (!($img = textimage_build_image('url', $preset, $text, $additional_text, $format))) {
    return FALSE;
  }
  drupal_goto($img);
}