Signwriter: Use TrueType fonts to replace text in headings, blocks, menus and filtered text

Last updated on
30 April 2025

The Signwriter module allows you to use TrueType fonts to replace text in headings, blocks, menus and filtered text. It does this by replacing text with an image generated from a TrueType font file which you provide. Note: Signwriter requires the GD library to function.

Signwriter has a number of features:

  • Multiple profiles allow you to have different settings for different headings.
  • Profiles can provide input filters to replace text matching a regular expression.
  • Images generated can be transparent or opaque.
  • Text can be positioned within a background image.
  • Text can be left, right, or center aligned.
  • Font size can be automatically reduced to fit the text within a specified maximum width.
  • Images are cached to improve performance under high load.
  • Generated images can be gif, png, jpeg, or bmp.
  • Themes can use profiles configured by a user, or create their own.
  • To fit text within a maximum width you can select to display multiple lines instead of reducing font size.
  • Drop shadows can be added to the text.

Font File Names

Please note that font file names, including the file name extension (.ttf) should all be in lowercase when using Signwriter. Otherwise Signwriter will not detect the file. See http://drupal.org/node/342280

The GD Image Library

Signwriter uses the GD Image library. GD comes installed by default in PHP >= 4.3, but can be enabled at compile time in earlier versions. If your PHP installation is on Windows, try uncommenting the line which reads 'extension=php_gd2.dll' in your php.ini.

Usage

You can use Signwriter to:

  1. Create a input filter to replace headings or custom tags in node text
  2. To generate headings in a theme
  3. To create menu heading and items
  4. To create block headings

You can create Signwriter profiles or create an on-the-fly profile and display the output in your template file or PHP.

Creating Profiles Under Drupal

A Signwriter profile is a collection of settings which can be used to create an image. To manage your profiles, go to admin>>settings>>signwriter. From here you can add, delete, or edit profiles. If you add or edit a profile, you will be taken to a profile settings page. On each profile settings page there are a number of options which may be set, each of which is explained on that page.

Using Filters

If a Signwriter profile has a pattern defined then it will be available as an input filter under admin>>input formats. After enabling the filter, any text matched by the pattern will be replaced with a Signwriter image.

Example: Replacing h2 headings in nodes

  1. Create a profile under admin>>settings>>signwriter called 'H2 Filter', making sure to enter /<h2>.*?<\/h2>/ under 'Pattern to Match When Used as a Filter'. There are some example patterns on the page.
  2. Go to admin>>input formats and edit your input format of choice. There should be an option to enable 'H2 Filter'.
  3. After enabling the filter, create a new page using your input format of choice. Make sure you put in at least one h2 heading: <h2>Signwriter filter test</h2>.
  4. Your headings should be replaced by Signwriter images in the submitted page.

Theme Development

To use Signwriter in a theme you have two options to configure it. You can enable the module in Drupal and configure it on the admin>>settings>>signwriter page by adding one or more profiles, or you can create profiles yourself using PHP.

Creating and Loading Profiles in php

If you are administering your profiles under Drupal, then in your theme code you will want to load one like this:
$profile = Signwriter_load_profile('Example Profile');
Note that you can pass a profile name or id to signwriter_load_profile().
As a PHP object, a Signwriter profile has the following fields, most of which correspond to a setting on the edit profile form:

$profile->text //The text to display. Can contain html entities.
                //For example, &amp; will be displayed as &
$profile->fontfile
$profile->fontsize
$profile->foreground
$profile->background
$profile->width
$profile->height
$profile->maxwidth
$profile->imagetype
$profile->cachedir // defaults to <Drupaldir>/signwriter-cache
$profile->textalign
$profile->transparent
$profile->bgimage
$profile->xoffset
$profile->yoffset

Any of these fields can be overridden in the theme after loading the profile.

If you want to create a profile from scratch then you will at least need to define $profile->fontfile all other settings will revert to defaults if not set. An advantage to creating the profile from scratch is that the module doesn't need to be enabled, and meddlesome users can't ruin your nice headings.

After you have loaded or created a profile you can use signwriter_title_convert or signwriter_text_convert to replace, for example, your $title in page.tpl.php (if you're using phptemplate).

Example 1: Replacing the page title in your theme

Note: This example is deprecated now and here for reference only. Signwriter 6.x now has an settings option can now be set to replace all page titles.

  1. Create a Signwriter profile in Drupal called 'Theme Heading', and assign the other settings to your liking.
  2. In your phptemplate theme add the following code to your page.tpl.php where you want to print the page title:
    if ($title != '') {
        $profile = signwriter_load_profile('Theme Heading');
        // at this point you could override any settings. for example:
        // $profile->fontsize = 43; // override the font size
        print signwriter_title_convert($title, $profile);
    }
    
  3. Refresh the page in Drupal and your title should appear in your custom font.

Example 2: Using Signwriter without configuring it in Drupal

  1. Add your custom font to your theme directory. In this example we'll use Arial.ttf.
  2. In your phptemplate theme add the following code to your page.tpl.php:
    if ($title != '') {
        $profile->fontfile = 'Arial';
        $profile->fontsize = 15;
        $profile->foreground = 'ff0000'; // red
        $profile->background = 'ffffff'; // white. If your text is jagged then change this to your page background colour
        $profile->maxwidth = 600;
        $profile->transparent = true;
        print signwriter_title_convert($title, $profile);
    }
    
  3. Refresh the page in Drupal and your title should appear in red Arial size 15 text.

Example 3: Using Signwriter for block titles

Note: This example is deprecated now and here for reference only. Signwriter 6.x now has an settings option can now be set to replace all block titles.

  1. Create a Signwriter profile called 'Block title'
  2. In your block.tpl.php, replace the code that prints your block subject with the following:
    $signwriter = signwriter_load_profile('Block title');
    $signwriter->text = $block->subject;
    $url = signwriter_url($signwriter);
    print '<img src="'. $url .'" alt="'. $block->subject .'" />';
    
  3. All block titles should now use your new Signwriter profile.

Thanks to momper for this example.

Example 4: How to change the colour of the output depending on taxonomy values on a node.

From #335767: How to alter the processing of signwriter_filter depending on a template variable ?

  1. Create a Signwriter profile in Drupal called 'Taxonomy' (or whatever name makes sense to you).
  2. Assign the profile settings as you require.
  3. Create a Vocabulary and some associated Taxonomy Terms
  4. In your phptemplate theme add the following code to your node.tpl.php where you want to print the page title (or other variable):
        $profile = signwriter_load_profile('Taxonomy');
    //Insert your own taxonomy logic here - this is just an example
    //This will locate term id 3 and alter the foreground colour
    if (array_key_exists(3, $node->taxonomy)) {
       $profile->foreground = 'ff0000';
    } else {
       $profile->foreground = '01e41a';
    }
    //Replace the $title value with whatever you want to output
        print signwriter_title_convert($title, $profile);
    
  5. Refresh the page in Drupal and your title should appear with a different colour based on the taxonomy term selected.

Example5: Signwriter for views nodes title

Here's how to get the node's titles within a view to work with signwriter. You'll have to make a tpl file for it in the end...kind of a drag but here we go:

1. The titles cannot be used as part of a global text. It has to be the just node title field straight up.

2. Make a file views-view-field--products-grid-display--title.tpl.php where "products-grid-display" was my view, and producttitles was my signwriter profile name.

3. Content of said file:

<?php 
$signwriter = signwriter_load_profile('producttitles');
$data = $row->{$field->field_alias};
$output = theme_signwriter_text($data, $signwriter);
print $output; 
?>

Help improve this page

Page status: Not set

You can: