gifwork

Utility for creating and maintaining animated GIF images V.1

by Louis JEAN-RICHARD
6 July 2000
Index
Introduction
At the start was the wish to create some nice animated picture like those you may encounter while surfing in the web. This prompted the author to look for a suitable tool to create animated GIF files. Unfortunately the discovery was that this various tools kill straightway your creativity with endless clicks through umpteen windows and in the worst case they even decide instead of you what has to come out. After various unsatisfactory attempts the author decided to create by own means a simple tool which combined with a performant image editor would lead to sounder results. It must be pointed out that when it comes to handling images those editors are always better than any of the mentioned tools. What is needed is only a tool who will merge your image sequence into an animated GIF file and subsidiarily will allow you to make rapid changes to the settings to fine tune the result. Those readers who would like to immediately put hands on GIFWORK may skip directly to the animation script and examples paragraphs which act also as a tutorial.
Scope and intended use of GIFWORK
The actual version of GIFWORK will run on any PC with DOS, WIN3.1, WIN9x, NT provided that you can open a DOS prompt window. It should also work on other operating systems providing a DOS emulation like LINUX.
Its main purpose is to merge the constituent images (or graphic elements) of the animation sequence (or cycle) into one single "animated" GIF file which can be integrated into HTML documents with an adequate editor. Another interesting feature is the ability to streamline an existing animated GIF file so as to make its file size smaller.
Accessorily you may also change selected settings of an existing animated GIF file, this usually without having to disassemble and reassemble it.
If you want people reading your pages to enjoy do not overload their computing resources with eternal download times and undisplayable animations, not everybody owns a "Ferrari" computer!
GIFWORK already by itself will help you to streamline an existing GIF file which takes to much space (and therefore increases disproportionately the download time when browsing in the web).
About GIF files
The Graphic Interchange Format (GIF) was introduced in 1987 by Compuserve with the aim to transmit efficiently simple graphics and images through its network. This file format has become very popular and it is not surprising that it was incorporated in the foundations of web browsing. The only new addendum since the 1989 specifications was a record where the number of repetitions of the animation sequence could be specified. The name of such a file gets the extension ".GIF". Those who would like to know more about this files will find useful links in the references paragraph of this document. In this document we will always refer to a file with this format when using the terms image file or GIF file.
Command syntax
The utility is invoked at the DOS command prompt  with
GIFWORK  [filename]  [ /optChar[+|-][arg] ]
 where   + means set,  - means reset, otherwise toggle is assumed. Do not write spaces between the option character and its argument. The order in which options are specified doesn't matter but note that they must follow the filename. The numeric argument 0 for options requiring a number may be omitted since it will be assumed. The default extension for the filename is ".GIF" whereas any other extension (even none) will tell the utility that you are passing an animation script file.
The output from the utility is always directed to the current directory. In order to avoid the inadvertent loss of existing files, the utility will interrupt a command that would overwrite a file and output a message to the console, unless you used (at your sole risk) the option "/O allow overwrite".
If no command option is specified the utility will assume that the filename passed as argument represents an animation script and will generate the GIF file according to its content. You may freely interrupt the utility with the standard keys Ctrl + C or Ctrl + Break.
Command options
More than one command option may be specified with one call to GIFWORK.
letter arguments Description
/A  m Write animation script, extract in sequence the individual images from the GIF file and generate a thumbnail in form of a HTML document. The script filename has the same as the extracted GIF file but with extension ".TXT" whereas the thumbnail has extension ".HTM". The single image filenames too get the name from the extracted file but with a progressive count number blended in at the end. The counter starts with 1. A potential conflict may arise when the file terminates with at least two digits; it can be avoided by renaming the GIF file. 
m=1 output too the unchanged settings to the script.
For more details see the the specific paragraph on animation scripts in this document.
See as example the thumbnail for "gifwork.gif".
/C  m Try to generate a streamlined animated GIF file with a smaller size. If the utility succeedes it will create a file with with 0 digits blended in at the end of the name taken from the submitted image. By adding the parameter m=1 it will try to handle unchanged areas surrounded by changing elements; this may bring a notable gain in file space but the trade off may be unwanted optical effects. The fact that not always a result is obtained is due to combinations of parameters which cannot be handled automatically. In those instances you can still obtain good results by giving a look to the animation script and using the other options offered by the utility. 
/F d Display information on the GIF file.
d=0 Display block details.
d=1 Display only block structure.
/H   Display a short help notice.
/M m The effect is similar to command option /A but the single GIF images output are always full size. This may be useful in certain circumstances when you need to reorganise an animation sequence.
/N p Ordinal position of the image in the animation sequence whose settings are to be modified. The list displayed on the console during the merge process or the animation script will help you in entering the right number.
(p is a number from 1 to effective number of images contained in the GIF file) 
/O   Allow overwrite of files. 
/P [index](r,g,b) Redefine the colour identified by index in the global colour map to the new values (r,g,b).
(index, r, g, and b are numbers from 0 to 255 and stand for red, green, and blue component of colour)
Global settings
This settings are specified on the first line of an animation script but can be altered directly in a GIF file.
letter arguments Description
/B index global background colour index. 
(index is a number from 0 to 255)
/E n global height in pixel of the image. This value can be set only in the animation script.
(n is a number from 0 to 65535).
/R n number of times the animation sequence has to be repeated. 
n=0 usually is interpreted as "repeat for ever...".
(n is a number from 0 to 65535)
/W n global width in pixel of the image. This value can be set only in the animation script.
(n is a number from 0 to 65535).
Single image settings
This options are used mainly in the animation script or in conjunction with the command option /N to alter in a GIF file individual image settings.
letter arguments Description
/D d disposal method:
d=0 no action required. (Note that depending on the browser used, this may cause various troubles)
d=1 Do not dispose. The graphic element is to be left in place.
d=2 Restore to background colour. The area used by the graphic element must be restored to the background colour.
d=3 restore the area used by the graphic element to what was there previously. (Unfortunately this mode is not implemented in all browsers!)
/T index Specifies which colour index is transparent. If you specify a number higher than 255 the transparency effect will be deactivated.
(index is a number from 0 to 255)
/U b b=0 means no user interaction expected.
b=1 means user interaction expected.
(this option should be ignored since user interaction never has been,  if at all,  implemented consistently)
/V t view time of image in 1/100s of a second.
After displaying the image element the program will wait this time before disposing it and displaying the next one. Do not take this timing for absolute since depending on the browser used the result may vary sensibly due to processing overheads.
(t is a number from 0 to 65535).
Ex.: t=100 means wait for one second
/X n horizontal position in pixel of the origin of the image element relative to the global origin of the image.
(n is a number from 0 to 65535).
/Y n vertical position in pixel of the origin of the image element relative to the global origin of the image.
(n is a number from 0 to 65535).
The animation script
The animation script is a simple text file which tells to GIFWORK how to assemble your animated GIF file. As paradigm we will use the script which helped to create the animated picture used as title of the present document. Before discussing the details let's have a look at it :
Here below is the content of the animation script "gifwork.txt" which directed the generation of the animated title for the present document. This are the images referenced in the script which were merged by the utility into the file "gifwork.gif"
gifwork.GIF /W200   /E32    /R10    /B0
gifwor01.GIF /V0     /D1 /X0     /Y0     /T0   /U0
gifwor02.GIF /V8     /D2 /X72
gifwor03.GIF
gifwor04.GIF
gifwor05.GIF
gifwor06.GIF
gifwor07.GIF
gifwor08.GIF
gifwor09.GIF
gifwor10.GIF
gifwor09.GIF
gifwor08.GIF
gifwor07.GIF
gifwor06.GIF
gifwor05.GIF
gifwor04.GIF
gifwor03.GIF
gifwor02.GIF
gifwork0.gif (200 x 32) 1373 bytes
gifwork1.gif (36 x 32) 425 bytes
gifwork2.gif (36 x 32) 391 bytes
gifwork3.gif (36 x 32) 358 bytes
gifwork4.gif (36 x 32) 275 bytes
gifwork5.gif (36 x 32) 202 bytes
gifwork6.gif (36 x 32) 302 bytes
gifwork7.gif (36 x 32) 363 bytes
gifwork8.gif (36 x 32) 397 bytes
gifwork9.gif (36 x 32) 421 bytes
(Hovering over the images will show info details.)
You will notice that the lines in the script follow exactly the command syntax but without the starting "gifwork". The first line determines how the generated GIF will be named and must specify the global settings like width, height, background colour, and repetitions of the cycle. Follow in sequence the lines, one for every image making up the animation, with filename and individual settings. View time, horizontal and vertical position relative to the global origin, disposal method, transparent colour, and user interaction may be specified in any order. If one of this individual settings is missing GIFWORK will use the last corresponding value it encountered before. This implies that you have to specify all of them on the second line in the script excepted transparent colour and user interaction, if they are not used. Note that the character case in the script doesn't matter. Although any name can be chosen for the generated GIF file it is good practice to leave it identical with that of the script which generated it. When reading the script file GIFWORK will ignore any text following an empty line. This is useful during the test phase since you can keep in the same file also variants etc...
Examples and Exercises
You can test this commands with the files from the download...!
Command Resulting effect
GIFWORK gifwork.txt
generate the animated GIF file "gifwork.gif" used as title for the present document.
GIFWORK gifwork.gif/F >gw.txt
Writes into "gw.txt" detailed information on the structure and settings of the animation file.
GIFWORK example /R50
will set the number of repetitions of the "example.gif" animation sequence to 50.
GIFWORK example.txt/O
After having modified the animation script "example.txt" the old image will be replaced with the new version. (caution when using /O)
COPY /b gifwork.gif gifworkh.gif
GIFWORK gifworkh.gif/N10/V100
GIFWORK gifworkh.gif/N18/V100
Creates a variant of the title animation where the "W" stops for a second after each inversion.
GIFWORK gifworkh.gif/P[30](243,230,20)
Changes the color #30  from black to yellow !
GIFWORK example.gif/A
REM In the script "example.txt" change in the third line /V4 into /V40 and save it
GIFWORK example.txt/O
This steps will slow down the animation of "example.gif"
GIFWORK gifwork/A1
Generates the animation script "gifwork.txt" from the file "gifwork.gif" and extracts its constituent images. The argument 1 causes all settings to be written, this is useful when several of them have to be modified and/or you want to reorganise the sequence.
gifwork.GIF /W200   /E32    /R10    /B0  
gifwor01.GIF /V0     /D1 /X0     /Y0     /T0   /U0
gifwor02.GIF /V8     /D2 /X72    /Y0     /T0   /U0
gifwor03.GIF /V8     /D2 /X72    /Y0     /T0   /U0
gifwor04.GIF /V8     /D2 /X72    /Y0     /T0   /U0
gifwor05.GIF /V8     /D2 /X72    /Y0     /T0   /U0
gifwor06.GIF /V8     /D2 /X72    /Y0     /T0   /U0
gifwor07.GIF /V8     /D2 /X72    /Y0     /T0   /U0
gifwor08.GIF /V8     /D2 /X72    /Y0     /T0   /U0
gifwor09.GIF /V8     /D2 /X72    /Y0     /T0   /U0
gifwor10.GIF /V8     /D2 /X72    /Y0     /T0   /U0
gifwor09.GIF /V8     /D2 /X72    /Y0     /T0   /U0
gifwor08.GIF /V8     /D2 /X72    /Y0     /T0   /U0
gifwor07.GIF /V8     /D2 /X72    /Y0     /T0   /U0
gifwor06.GIF /V8     /D2 /X72    /Y0     /T0   /U0
gifwor05.GIF /V8     /D2 /X72    /Y0     /T0   /U0
gifwor04.GIF /V8     /D2 /X72    /Y0     /T0   /U0
gifwor03.GIF /V8     /D2 /X72    /Y0     /T0   /U0
gifwor02.GIF /V8     /D2 /X72    /Y0     /T0   /U0
COPY /b gifwork.gif gifworkm.gif
GIFWORK gifworkm /N3 /X75
GIFWORK gifworkm /N4 /X77
GIFWORK gifworkm /N5 /X82
GIFWORK gifworkm /N6 /X87
GIFWORK gifworkm /N7 /X84
GIFWORK gifworkm /N8 /X79
GIFWORK gifworkm /N9 /X76
GIFWORK gifworkm /N10/X73
This series of commands will create a variant of the title animation where the rotating axis of the "W" moves toward the right and back at every odd inversion. This kind of manipulation is done more effectively by copying and modifying the animation script. As you may notice the images whose positions were altered need to be edited in order to obtain a clean animation. (The empty right part of this images must be clipped off)
GIFWORK gifwork/C
The streamlined file "gifwork0.gif" will be generated with filesize reduced to 4894 bytes.

example.gif

Exercices:
  1. Modify "example.gif" so as to eliminate the final vibration.
  2. make appear the ball in "example.gif" deccelerating.
  3. Re-examine the "gifwork.txt" animation script and modify it in such a way as to save one step without altering the perceived effect.
Some practical hints
Content of the download archive
Simply unpack the content of the archive into a directory of your choice. If you want to use the utility from different directories you may move it into the windows directory or add to the search path the name of the directory where it is located.
GIFWORK.EXE         33'760    utility program
GIFWORK.HTM         26'478    documentation
GIFWORKT.HTM         3'257    thumbnail example
README.TXT           1'082
GIFWORK.GIF          5'513    animated title image
GIFWORK.TXT            338    animation script
GIFWORK0.GIF         1'373    single GIF files
GIFWORK1.GIF           425
GIFWORK2.GIF           391
GIFWORK3.GIF           358
GIFWORK4.GIF           275
GIFWORK5.GIF           202
GIFWORK6.GIF           302
GIFWORK7.GIF           363
GIFWORK8.GIF           397
GIFWORK9.GIF           421
EXAMPLE.GIF          8'433    another example
References
Graphics Interchange Format  a practical overview by Jörn Daub.
GIF89a - The original specifications from CompuServe.
The Graphics File Formats Page An alternative site with related documentation.
GIF animation on the www maintained by Royal Frazier.
Consult the web site www.ljr.ch for updates etc...


©2000 Louis JEAN-RICHARD, All Rights Reserved.