Annotate Image Ant Task

The <annotateimage> Ant task allows you to annotate an image with text. It can be used to automate steps in a build such as stamping an image used for a splash screen or in an About dialog with release/version information of the build.

Currently only JPEG images are supported. (TO DO: add GIF support... need a locate Java impl of a writer)

The image to be annotated may be either updated in-place or obtained from a source and used to create an annotated image in the specified target location.

The font to be used for the annotations is specified by indicating the font family, optional style attribute such as italic and bold, and the point size to be used. The font name may be either the name of a specific font family or one of the following logical font names:

The font family names that are available are platform-specific and may depend on the comfiguration of the build machine. A default font is used if font attributes are not specified.

The content and position of the text annotations are defined in nested <annotation> elements. The position of the text annotation line(s) is specified by the { x, y } coordinate of the upper left corner of the area in which the annotation is to be drawn. The position is specified relative to the { 0, 0 } upper left coordinate of the image.

Installation

To use this optional task, place the jar file in your %ANT_HOME%/lib directory and include the following optional task definition in your project buildfile:

     <taskdef name="annotateimage" classname="com.glaivestone.ant.taskdefs.AnnotateImage"/>
 

Attributes

type
(optional) image file type (encoding): JPEG (default)
 
imagefile
pathname of the annotated image file to be created or updated.
 
imagesource
(optional) pathname of the source of image to be annotated. If not specified, the target imagefile is modified.
 
font
(optional) name of the font to use
 
bold
(optional) boolean indicating whether to use bold style font
 
italic
(optional) boolean indicating whether to use italic style font
 
fontsize
(optional) integer value of the point size of the font to use
 
color
(optional) color for the text; default is black
Supported color names: black, white, red, yellow, blue, green
 

Content

One or more nested <annotation> elements are defined to specify the position and content of the text annotations. An annotation is added in a text area specified by the upper left corner relative to the containing image. If multiple lines of text are specified, each subsequent line after the first is positioned at the left margin of the text area and down one line from the preceding annotation.

A single-line annotation is specified using the text attribute. Multiple-line annotations are specified by specifying one or more lines of text content within the <annotation> element. Multiline annotations are trimmed of leading and trailing blanks before being positioned in lines of text starting from the top of the text area.

x
x coordinate of the upper left corner of the text annotation area
 
y
y coordinate of the upper left corner of the text annotation area
 
text
the line of text with which to annotate the image
(omitted if the text line(s) are specified as element content)
 

Example Usage

In-place update using the default font to insert one line of text

    <annotateimage imagefile="${build.dir}/splashscreen.jpg"
            fontsize="10">
        <annotation x="100" y="100" text="Release 1.0"/>
    </annotateimage>

In-place update using a specific font to insert two lines of text

    <annotateimage imagefile="${build.dir}/splashscreen.jpg"
            font="SansSerif" bold="true" italic="yes" fontsize="14"
            color="red">
        <annotation x="150" y="200" text="Release 1.0"/>
        <annotation x="100" y="220" text="Nightly build: ${DSTAMP}"/>
    </annotateimage>

Annotate a template image with multiple lines of text

    <annotateimage imagefile="${build.dir}/splashscreen.jpg"
            imagesource="splashscreen-template.jpg"
            font="Serif" bold="true" italic="yes" fontsize="14">
        <annotation x="20" y="100">
            Release 1.0
            (development build)
        </annotation>
    </annotateimage>


Created by D. Lewis on 22-Oct-2002. Idea and prototype from G. Gregory.