| HOME | |||||||||||||||||||||||||||||
|
Making XML image description files For more information contact us at info@psoft.net |
|||||||||||||||||||||||||||||
|
Images that are described in the xml image file are loaded by the program in the form of
"trees", which each image being made up of a number of nodes. The root of each tree is the
place to set global image parameters. The xml file consists of one big "<images>" tag. Between the opening and closing of the <images> tag, each individual image is described. (This is done with the <image> tag. Note that the word "image" is singular in this case.) Each <image> tag is self-contained, and has no relation to any other <image> tag, with the exception that it must be given a name that is unique within the scope of the XML file. |
|||||||||||||||||||||||||||||
So the skeleton of the XML file would look something like this:
<images> <image name="image1"> . . . </image> <image name="image2"> . . . </image> . . . </images> |
|||||||||||||||||||||||||||||
From here on, we will concentrate on the structure of the <image> tag itself. This tag can be
given a large number of parameters. The parameters can be assigned inside the <image> tag itself
as in
<image param_name="param_value"> . . . </image>or using a <param> tag inside of the <image> tag. <image> . . . <param name="param_name">param_value</param> . . . </image> |
|||||||||||||||||||||||||||||
|
While there is no functional difference between the parameters defined in these two ways, for
keeping to convention, and better readability, you should define the image name and values
relating to the image's physical properties (i.e. format, size, color depth, transparency)
right inside the <image> tag, and define miscelaneous properties using the <para> tag.
(Note that the order of parameter definition plays no role here) No parameters other than "name" are required by the <image> tag, however you may wish to specify some to let image maker know what kind of image you want constructed:
|
|||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||
|
The actual image is built using a combination of image operations (defined by the <imgop> tag)
and primitives (such as lines, circles and rectangles). The <image> tag may contain only ONE
primitive or operation tag. (In most cases it will be an <imgop> tag that will put together
the image) Every <imgop> tag MUST have a "type" parameter, which specifies the type of operation you wish this node toperform. As a rule, operations will have "children" that they work with. These children can be either primitives, or results of other operations. Some operations, such as addition or overlaying, can have unlimited children. Others can only have two or one (like the maskedfill operation). A special case is the "file" operation, the result of which is an image loaded from a file. It can have no children. The "file" operation must have an "src" parameter, that indicates the local path or the URL from which to retrieve the image file. Many graphical formats are currently supported, but it is recommended that you stick to using either gif or jpg files. Png file support is available but the alpha channels are not handled properly at this time. The simplest image definition would be
<image name="static_image">
<imgop type="file" src="image.gif">
</image>
This would load an image from the file "image.gif" and draw it on the image you are building.
It's not very useful since you could have just as easily used the original image.gif, but it's
a start.In addition to the "type" and "src" parameters, which are mandatory, the <imgop type="file"> operation can have two optional parameters:
|
|||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||
The most basic operation other than "file" is the "overlay" operation, that simply draws its
children one onto another. Here is an example of using "overlay" with the "circle" primitive
for drawing olympic rings:
<image name="olympic" bgcolor="#000000">
<imgop type="overlay">
<circle x="20" y="20" radius="20"/>
<circle x="35" y="20" radius="20"/>
<circle x="50" y="20" radius="20"/>
<circle x="27" y="35" radius="20"/>
<circle x="43" y="35" radius="20"/>
</imgop>
</image>
The use of the <circle> tag here is pretty clear. Note that <circle> is a primitive, and
can therefore have no children. The primitives supported by the image maker are<circle>, <line>, <rectangle> and <oval> Each of the primitives must have a certain set of parameters in order to be drawn properly, and can also be supplied additional, optional parameters, that will specify drawing options. The neccessary parameters are:
|
|||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||
As stated above,these parameters are just the minimum required ot get the shape to be drawn. You can specify optional parameters to pass to the primitive tags to alter the way in which they are drawn. These are listed below:
|
<image name="olympic">
<imgop type="overlay">
<imgop type="file" src="flag.gif"/>
<circle x="20" y="20" radius="20" color="#0000FF"/>
<circle x="35" y="20" radius="20" color="#000000"/>
<circle x="50" y="20" radius="20" color="#FF0000"/>
<circle x="27" y="35" radius="20" color="#FFFF00"/>
<circle x="43" y="35" radius="20" color="#00FF00"/>
</imgop>
</image>
But what if you already have a ready image of the symbol that you wish to be
painted on top of an image of a background? You could use the code:
<image name="olimpic">
<imgop type="overlay">
<imgop type="file" src="flag.gif"/>
<imgop type="file" src="rings.gif"/>
</imgop>
</image>
This would draw the image rings.gif on top of flag.gif, and return the result.
(rings.gif should be a transparent gif for best results). However the code would only
give you the result needed if the images are the same in size, and the rings are already
centered in the rings.gif image:
| flag.gif | rings.gif | result |
![]() |
![]() |
![]() |
![]() |
In this case the result will be | ![]() |
<offset x="20" y="10"> <imgop type="file" src="rings.gif"/> </offset>An offset tag makes everything that is drawn inside of it move over by the given amount of pixels, so that for all the nodes inside that tag, the coordinate (0,0) is physically located at (x,y) in the parent image. In the case of the rings.gif node, it would receive a sub-image of the main image that has its upper-left corner at x=20 and y=10:
![]() |
||
Using a combination of <imgop type="overlay"> <imgop type="file"> and <offset> tags, it is possible to build a large image from a number of smaller pieces:
<image name="collage"> <imgop type="overlay"> <imgop type="file" src="a.gif"/> <offset x="20" y="0"> <imgop type="file" src="b.gif"/> </offset> <offset x="0" y="20"> <imgop type="file" src="c.gif"/> </offset> <offset x="20" y="20"> <imgop type="file" src="d.gif"/> </offset> </imgop> </image>The above code, assuming images a through d .gif measure 20x20 pixels would create a composite as follows:
+---+ +---+ | A | | B | +------+ +---+ +---+ => | A B | +---+ +---+ | C D | | C | | D | +------+ +---+ +---+We have already discussed the <imgop type="overlay"> and <imgop type="file"> operations. There are three more that are currently supported by image maker: <imgop type="add">, <imgop type="greymask">,<imgop type="shadow"> and <imgop type="maskedfill">.
The result of the "add" operation, simplest to understand, is nothing more than arithmetic addition of it's children's outputs. For example if one child paints a pixel with red color and another paints it with blue, the resulting pixel after addition would be purple, since
#FF0000 +#0000FF ========= #FF00FFif a green pixel was later added, the result would be white:
#FF00FF +#00FF00 ========= #FFFFFFNote that each color channel is limited to the value of #FF, and there is no overflow into other color channels. so #0000FF + #0000FF would result in #0000FF, not #0001FE.
The "add" operation must have at least two child nodes. There is no upper limit on this number.
The "shadow" opertion is really simple and basic. It can have only one child, from which it will cast a shadow. It can accept the following parameters:
|
<imgop type="shadow" dx="5" dy="5" blur="3" color="#440000" opacity="0.5">
<circle x="10" y="10" radius="9" color="#FF0000" fill="true" />
</imgop>
The "greymask" operation is used to change apply a grey gamma mask to an image. This means that
a greyscale image, or a "mask" is used as a guide to make some pixels of the source image
lighter, and others darker. Pixels that are colored 50% grey (#808080) on the mask are
left unchanged on the source image. pixels darker than 50% grey are proportionately darkened,
and pixels that are lighter are in turn lightened. The change of gamma value on the source
pixel is proportional to how much darker or lighter the mask pixel is than the 50% grey.The "greymask" operation needs two children to work properly:
+---------------+ Key: |++++++++++++++=| + : light grey |+=============-| = : 50% grey |+=============-| - : dark grey |=--------------| +---------------+If this image is stored in a file called mask.gif, you can apply this mask using the following code:
<imgop type="greymask"> <imgop type="file" src="mask.gif"/> <imgop type="file" src="image.gif"/> </imgop> </font></pre>To simply create a beveled area of some color, you can omit the second child and insert a "color" parameter in its place:
<imgop type="greymask"> <imgop type="file" src="mask.gif"/> <param name="color">#00FF00</param> </imgop>This code would create a beveled green rectangle. The color parameter is ignored if a second child is present.
The "greymask" operation will ignore all children after the first two, and will cause an error unless it has either two children (mask and source) or one child (mask) and a color parameter.
Finally we have the "maskedfill" operation. While its functionality is not very difficult to grasp, it is quite powerful and offers a number of options if used properly. The basic purpose of the maskedfill operation is to allow copying an image from source to destination using a separate alpha mask to determine the shape and opacity of the area to be filled.
A mask for this operation is a greyscale image, in which a black pixel indicates full transparency, a white pixel indicates full opacity and a grey value means that the source pixel will be translucent, with it's alpha value determined by how light the pixel on the mask is. If the purpose of the mask is to convey a simple shape, then just the black and white colors will suffice, though grey values can be added along the border for antialiasing.
The "maskedfill" operation can have two children:
|
The <label> tag needs to have two child tags:
<label>
<font face="Times New Roman" size="14" bold="true"/>
<text>Label text goes here</text>
</label>
As you see, the <font> tag receives parameters indicating the name of the font to use
("face") and the size to use ("size"). The font name should correspond to it's identifier as
perceived by your system. Additionallly, the <font> tag may include the "bold" and "italic"
parameters, that, if set to "true" will cause the font to become bold and italic respectively.
(Note that all values other than "true" will be ignored for these parameters)The <label> tag itself can also take a number of parameters:
|
The arguments in parameter values must begin with a dollar sign ($). The declaration will look like this:
<circle x="10" y="10" radius="5" color="$color"/>
This means that the color of the circle is to be looked up at the time of image generation
from an argument called "color". The declaration can also take the form of
<param name="color">$color</param>
Arguments can be used in vitually all parameter values of the xml declaration. Two notable
exceptions are the "name" parameter of the <image> tag and the "type" parameter of the
<imgop> tag.Here is and example of the use of arguments:
<image name="dynamic_label">
<label color="$textcolor">
<font face="Times New Roman" size="$size"/>
<text>$text</text>
</label>
</image>
</font></pre>
This code will generate an image that contains a string of user-specified text, in
a user-specified size of the Times New Roman font, painted in the user-specified color.
The arguments textcolor,size and text will need to be provided to image maker at the
time that the image is built.While this is not neccessary, it is a good style to declare what arguments will be needed to properly build a given image. (Providing this information also helps automate the invokation of image maker later on.) To this end, you should use the "arguments" parameter of the <image> tag. This parameter's value should be all the needed arguments listed in a comma-separated string with no spaces. For example the image definition of the above label with an added "arguments" parameter would become
<image name="dynamic_label">
<label color="$textcolor">
<font face="Times New Roman" size="$size"/>
<text>$text</text>
</label>
<param name="arguments">textcolor,size,text</param>
</image>
</font></pre>
Using arguments s very convinient in conjunction with the <imgop type="file">
operation. Because it provides the option of including a "base" parameter, you
can code all your image paths relative to a base directory, which you can set as
an argument:
<imgop type="file" src="images1/mypic1.gif" base="$img_path"/> <imgop type="file" src="images2/mypic2.gif" base="$img_path"/> <imgop type="file" src="images3/mypic3.gif" base="$img_path"/>Then you can set the img_path argument to different values depending on where your image base is located. Or if it moves to a remote server, you can set the argument to the base URL. (i.e. "http://www.remoteserver.com/~mydir/")