Chapter w5: WebCollage for Images

StarNine's WebCollage is a unique Web graphics tool - in fact, it's in a class by itself. Its primary purpose is to produce customized graphics on a schedule for Web use. These graphics can be automatically transferred by FTP to a remote server. WebCollage can also be used as a production tool to produce custom graphics like mastheads and rollovers.

The WebCollage software is comprised of two applications, the Editor and the Assembler. You design templates in the Editor that can include script shapes to display text results from special compiled AppleScripts. Once you've created your template and any scripts for script shapes, you can produce graphics either periodically or on demand with the Assembler.

In this chapter, we'll look at creating compiled scripts to use with script shapes in WebCollage templates. We'll also use WebCollage as a production tool to batch produce masthead graphics.

Scripting WebCollage

Both the Editor and the Assembler support AppleScript with similar dictionaries. The most productive use of AppleScript with WebCollage, returning data to script shapes in templates, is not easy to understand by looking at the dictionaries. You will need to be familiar with WebCollage already to make use of this chapter. Review WebCollage's documentation, especially about script shapes.

WebCollage expects a number of special event handlers to appear in any compiled scripts used with script shapes. Within those handlers, on process and on processShape, we can access the properties of the template's shapes. Figure w5. 1 shows the many properties available for a WebCollage shape.

Scripting graphics


 

Fig. w5.1  WebCollage's dictionary entry for the shape object class shows the many properties that we can modify via AppleScript.

Scripting WebCollage

All the scripts that follow were designed and tested for WebCollage 1.0.1.WebCollage is published by StarNine Technologies, who can be reached at http://www.starnine.com/.

Returning data to a WebCollage template

This script (Code w5.1) is intended to be called by a script shape. For this to occur, the script must be saved as a compiled script in the same folder as the WebCollage template file that contains the script shape.

Figure w5.2 shows the first step in creating a script shape in WebCollage Editor: selecting the script shape tool from the toolbar. Figure w5.3 shows the settings for our sample script shape, set to retrieve its value from our script named "w5.1". Figure w5.4 shows the results of the template generating a graphic.

To return data to a WebCollage template:

  1. on process(myShape)

    We define our process handler to receive the reference for the script shape from WebCollage when the template is processed. For information on process, see the sidebar About script shapes or review WebCollage's documentation.

  2. set myData to word 1 of the ((current date) as string)

    Now we set a variable to hold the weekday name of the current date.

  3. return myData
    end process

    Finally, we return the weekday name stored in the variable to WebCollage. This data, the string of the weekday, gets sent back to WebCollage, which uses the string as the text in the template as it rasterizes it into a bitmap GIF image.

Code w5.1. This script returns the current weekday name to a WebCollage script shape.

on process(myShape)
set myData to word 1
of the ((current date)
as string)
return myData
end process

About script shapes

When you want to create an object in your template that contains data from an AppleScript, you place a script shape in your template using the WebCollage Editor. This shape's contents are set when the template is assembled, calling the script attached to this shape.

Each script shape contained in a template can be scripted by saving a separate compiled script that includes a handler to respond to the special process event. The process event occurs immediately after a URL shape fetches its data or when a script shape wants its data. The value your script's handler returns becomes the contents of the script shape as graphical text.


 

Fig. w5.2  The WebCollage Editor's toolbar includes a tool to create a script shape, which is shown selected here.
 


Fig. w5.3  The WebCollage Editor's Script Options window can be opened by double-clicking on a script shape in your template. This Script Options window shows the settings for our sample script shape, which in this case retrieves its value from a complied script named "21.1"
 


Fig. w5.4  If you preview your new WebCollage template, you should see something like this image, showing how our script has returned the current weekday name to WebCollage for inclusion in the image produced.

Returning data from FileMaker Pro to a WebCollage template

This script (Code w5.2) returns FileMaker Pro data to a script shape. To do this properly, the script must be saved as a compiled script in the same folder as the WebCollage template file that contains the script shape.

Figure w5.5 shows the settings for our sample script shape, set to retrieve its value from our script named "w5.2". Figure w5.6 shows the results of the template generating a graphic.

To return data from FileMaker Pro to a WebCollage template:

  1. on process(myShape)

    First we define our process handler to receive the reference for the script shape from WebCollage when the template is processed.

  2. set myField to url of myShape

    Now, we store the url property of the script shape in a variable. We'll use the value that is in the url property as the name of the field in the FileMaker Pro database.

  3. tell application "FileMaker Pro"
    set myData to cell myField of current record
    end tell

    Next, we retrieve the value of the cell with the same name as the script shape url from the current record of the current FileMaker Pro database. We can access any cell by placing that cell's name in the script shape's url property. Just edit the template with the script shape in WebCollage Editor.

  4. return myData
    end process

    Finally, we return the data to WebCollage.

More on FileMaker Pro

Code w5.2. This script returns from the current record the value of the field with the same name as the script shape's url property.

 on process(myShape)
set myField to url of myShape
tell application "FileMaker Pro"
set myData to cell
myField of current record
end tell
return myData
end process


 

Fig. w5.5  This template shape's Script Options window shows the settings for our sample script shape, which in this case retrieves its value from a complied script named "w5.2"
 

 

Fig. w5.6  If you preview your new template, you should see something like this image, showing how our script has returned the contents of the FileMaker database field "subtitle" to WebCollage for inclusion in the image produced.

Batch producing repeating elements like mastheads

You can use a WebCollage template in conjunction with a FileMaker database and a stand-alone script application to quickly build final, ready-to-use GIFs. Figure w5.7 shows a WebCollage template with two script shapes, both pointing to Code w5.3, which we'll name Graphics Builder Script. Figure w5.8 shows the url setting for our title text script shape. Figure w5.9 shows the url setting for our subtitle text script shape. Figure w5.10 shows the FileMaker Pro database our scripts use to generate the custom graphical title and subtitle in the mastheads. Figure w5.11 shows a sample file produced by running Code w5.4, the Graphics Builder Master script application.

To batch produce repeating elements like mastheads:

  1. Our process handler, Code w5.3, is based on Code w5.2.

  2. set myFolder to (choose folder with prompt "Select folder to save graphics to:")

    The following steps illustrate the stand-alone script application shown in Code w5.4. It begins by prompting the user for a folder to save the graphics into.

  3. tell application "FileMaker Pro" to set myRecords to number of records

    We have FileMaker put the number of records in our database into the variable myRecords.

  4. repeat with myCurrent from 1 to myRecords

    Next, we start to repeat through each record in the database.

  5. tell application "FileMaker Pro" to set data cell "current" to myCurrent

    Here we set the global field in FileMaker named "current" that our two shape scripts use to decide which record's data to use when producing graphics.

  6. set myFile to myFolder & myCurrent & ".gif" as string

    Now we set up a file name for our soon-to-be-generated GIF file and store it in the variable myFile.

  7. tell application "WebCollage Assembler" to assemble "Graphics Builder" in myFileend repeat

    Finally, we have the WebCollage Assembler generate the graphic and save it in the file specified by myFile.

Code w5.3. This script is to be used with a WebCollage template's script shape.

on process(myShape)
tell application "FileMaker Pro"
set myCurrent to
cellValue of cell "current"
set myCurrent to
myCurrent as integer
if myCurrent > number
of records or myCurrent
< 1 then set myCurrent to 1
set myTitle to cellValue
of cell "title" of record
myCurrent
set mySubtitle to
cellValue of cell "subtitle"
of record myCurrent
if (url of myShape)
= "title" then
return myTitle
else
set myCurrent to
myCurrent + 1
if myCurrent > number
of records or myCurrent
< 1 then set myCurrent to 1
set data cell "current"
to myCurrent
return mySubtitle
end if
end tell
end process

 

Fig. w5.7  Our template, as shown in the WebCollage Editor, has two script shapes in it, each script shape calls the same script, which we have saved with the name "Graphics Builder Script".
 

Fig. w5.8  This shape's Script Options window shows the settings for our script shape, which in this case retrieves its value from our complied script named "Graphics Builder Script". By setting the script shape's URL field to the value "title" we have our script retrieve the FileMaker Pro field of the same name.