GIFBUILDER
is a universal object in TypoScript that uses some basic TypoScript code to generate images using the ImageMagick (or GraphicsMagick) library in PHP. Generating images with ImageMagick is normally very complex, and we would have to learn a fair amount of PHP to make anything. Using GIFBUILDER
, makes it relatively easy to make these same dynamic images without learning PHP or opening Photoshop. GIFBUILDER
can actually be used for any images that we would want to create in TypoScript, but we are going to be using it specifically for GMENU
in this book to turn our text fields into typographic images complete with layers and effects.
We are going to learn about three main objects in GIFBUILDER
that will help us create our menu items:
A complete list of the properties available to GIFBUILDER
is beyond the scope of this chapter, and not really necessary to build most menus. If you want to learn more about GIFBUILDER
, I recommend Mastering TypoScript by Daniel Koch. If you have any problems with GIFBUILDER
, you may need to check your ImageMagick configuration in the TYPO3 Install Tool.
The BOX
object is one of the key TypoScript objects in GIFBUILDER
. The BOX
object is, like it sounds, just a simple graphical box defined by its size and color. By itself, it's not that helpful, but we can add boxes as layers to generate borders and backgrounds that will be flattened into our final generated images. We are only going to use two properties for our boxes:
Here is an example of a gray box, 400 pixels wide, 20 pixels tall, and offset 3 pixels down and to the right:
lib.subMenu.1.NO { 5 = BOX 5.color = #aaaaaa 5.dimensions = 3,3,400,20 }
The next object we can use, IMAGE
, will bring in an image for normal display or basic tiling and masking. The IMAGE
object can be used for complex displays, but we are only looking at menu applications and will just look at a few options:
Property |
Description |
---|---|
|
We can declare point to a filename or use a use a complete 10.file = fileadmin/templates/image.png 10.file { import = uploads/media/ import.field = media import.listNum = 0 width = 15 height = 10 } |
|
This is the x, y offset from the layer beneath it. |
|
We can tile the image x, y times inside the |
Finally, we're going to look at the options for a TEXT
object in GIFBUILDER. TEXT
objects are used to display any text we want in GIFBUILDER
, but will be mainly using them to show the title of each page as a menu item. This list of properties is much more exhaustive because this would obviously be one of the most important objects to customize when we're creating a menu using graphical text:
Property |
Description |
---|---|
|
This is the field from the menu item we want to use for the text. We are going to use |
|
As we are rendering this text as a graphic image, we don't need to rely on browser-safe fonts. We can point this to any font file that we are licensed to use to generate our images. This is one of the most important reason to look at using |
|
This is the font size of our text. |
|
This is the color of our text. |
|
Like the other objects, we can define an offset from the layer before this. |
|
We can align the text to the right, left, or center. |
|
We can set the angle to display the text at. For a 45 degree angle, we could say |
|
If set, this will render small text cleaner by generating the text at twice its font size scaling it down to the correct size using ImageMagick on the server. Unfortunately, this can be CPU-intensive so we should only use it in production if we've tested it with and without and decide whether we need the functionality. |
|
We can render the text with a shadow and define its x, y offset. |
|
This defines the color of the shadow. |
|
We can change the blur of the shadow with values 1-99. |
|
If blur has a value, we can set the opacity of the shadow from 0% (transparent) to 100% (opaque). Example of 80% opacity: 10.shadow.opacity = 80 |
|
We can set the intensity of the shadow from 0 to 100. |
|
We can also use an emboss effect on our text using properties similar to the shadow properties. |
|
This sets the upper border color of the emboss effect. |
|
This sets the lower border color of the emboss effect. |
We work with GIFBUILDER
by creating new objects for the GIFBUILDER
, designing them with properties, and layering them by number values. Each layer is stacked in ascending order (larger numbers on top), and then TYPO3 generates a final image by flattening all of the layers into one image. It sounds a little complex, but look at this example:
lib.subMenu.1.NO { 5 = BOX 5.color = #aaaaaa 5.dimensions = 3,3,400,20 10 = TEXT 10.text.field = title 10.fontSize = 12 }
In the example that we just saw, lib.subMenu.1.NO
is our GIFBUILDER
object. Although the numbers used to identify objects (5 and 10
in the example) are sometimes arbitrary in TYPO3, they are very important for GIFBUILDER
because they define the ordering in layers. GIFBUILDER
stacks it's subobjects from lowest number to highest. So, in the example that we just saw, TYPO3 is generating an image in a logical sequence:
Using this system, we can stack very simple objects on top of each other to draw basic buttons.
The GIFBUILDER
object will apply itself to all items in a GMENU
menu. For the basic GIFBUILDER
object, we are only going to look at two properties:
XY
defines the size of the image (width and height)backColor
defines the background color for the entire imageThe interesting trick for XY
(and some of the other dimension properties) is that it can be based on hard-coded numbers and TypoScript constants, or it can be a calculation based on the size of another item. In the following code, the size of the GIFBUILDER
object is tied directly to the size of the TEXT
object declared below it:
10 = TEXT 10.text.field = title XY = [10.w]+10,[10.h]+10
The references [10.w]
and [10.h]
read the current width and height of the object associated with 10
. Then, we add 10 pixels onto each one to give ourselves a little bit of room for spacing. We'll use this technique in GMENU
to make sure that our boxes and graphic objects always line up with our titles.
18.191.208.181