This page describes using DP to create image files showing numbers, such as the image inside these borders: . The numbers can be up to ten digits.
A DataPerfect database is provided, in which a number is entered. Then a report is run which creates the GIF image containing the number.
The Graphics Interchange Format(c) is the Copyright property of CompuServe Incorporated. GIF(sm) is a Service Mark property of CompuServe Incorporated.
The specification can be found at http://www.w3.org/Graphics/GIF/spec-gif89a.txt.
The database can be put to immediate use to generate an image, by following these instructions.
Create a new folder for your project.
Download COUNT.STE
into that folder and then
use the dpimp.exe
program to create the DP structure file.
Download counters.zip and un-zip into the same folder which contains the DP structure file. The 32 files will be used by the database to create image files.
Enter the database (use the program dp.exe
), and type in a number.
Use Shift-F7 to go to the report list and navigate to the report named
"Direct creation of image file", and
adjust the output file name if desired.
Finally, Shift-F7 again to produce the GIF file.
For subsequent numbers in the same session,
you would be able to use Alt-F7.
The need for an image that shows a number came up when I needed a page view counter for the home page of Know & Enjoy Mexico (KEM). Since the home page is a static HTML file, there is no way to embed a changing value in it, so I devised a CGI script which generated a GIF file on the fly. The output of this script is seen by the browser to be a GIF image which it then presents in-line.
I began working on this problem in October of 2001. By June of 2002, I had finalized the base image of digits, . Each digit is a separate image, and they follow one another in the data stream of the GIF file. This base image was used for about 10 years by a Firestorm program countg.c for general counting, and other programs specific to particular Firestorm applications such as KEM. These programs lay down the digits from left-to-right.
You can still see a visitor count near the bottom of the KEM home page. But since Firestorm has been retired, the image is now produced by a simpler CGI script p70r5.cgi, implemented in the Bash shell scripting language, which is widely available on Linux systems. For simplicity of coding, this script lays down the digits right-to-left.
In June of 2011, with the impending retirement of Firestorm, I broke the base image up into fragments, each fragment in a separate file. This allows the creation of number images from a command line (as described below), and allows for the simpler CGI script coding.
The technique, as supported here, allows for displaying numbers up to 10 digits long. It uses fragments of a valid GIF file, and combines them to create the final image. The database comes with two reports, the first of which does not generate the GIF file directly, but rather generates a batch file, which, when run, creates the GIF file. The second report directly generates the GIF file by combining the fragments appropriately.
The bits and pieces of GIF file are contained in counters.zip. When extracted, there will be 32 pieces:
The image is constructed by putting together the pieces as follows:
First, a header specifying the desired width. For example, H\5 for a five digit number.
Then, for each digit, a separator, followed by a position indicator, followed by the digit. For example, S then P\0 then 7, for the digit seven in the first (left-most) position. This is repeated for each digit to be in the image.
Finally, the terminator.
For example, to display the number 1957, we could use the DOS copy command, as shown here:
COPY /B H\4+S+P\0+1+S+P\1+9+S+P\2+5+S+P\3+7+T 1957.gif
This would concatenate all of the pieces to create a
file named 1957.gif
which would be an
image displaying that
number.
In Linux, one would use this command to create the same image file:
cat H/4 S P/0 1 S P/1 9 S P/2 5 S P/3 7 T >1957.gif
Note that this next command would produce a different image file, but containing the same apparent image. The digits are laid out in the file from right-to-left.
cat H/4 S P/3 7 S P/2 5 S P/1 9 S P/0 1 T >1957.gif
The DP report is quite simple.
It first sets rv3 to the number as a string. Then it sets rv2 to the length of that string. Then it sets rv1 to the size of header needed (from 1 to X). Finally, it sets rv7 to the filename of the appropriate header, and includes that file into the report output.
Next, it starts a virtual subreport to the same record, counting down in rv2, and repeating the report body for that record until rv2 has reached zero. For each digit, it includes the file named S, and the position file for the current value of rv2, and the file for the particular digit. After the subreport closes, it includes the file named T, and stops the report.
It uses three possibilities introduced fairly recently into DataPerfect. A virtual subreport is used to begin handling the digits. The technique of repeating the report body for the same record is used to handle the digits one by one, from right to left. The technique of including an external file into the report output is used to bring in each of the needed fragments.
This technique can be used for any image that is to be built up from rectangular tiles.
In the number usage, the canvas can contain from 1 to 10 tiles across, and one tile high. Each tile is 10 pixels wide and 20 pixels high.
To divide a canvas using a different tile size would require appropriate header files, position files, and each possible tile.
Use a image editing file to produce a sample of the right size,
then use the DOS debug
command, together with
the GIF specification to figure out the various pieces.
Finally, construct a DP database with a panel that specifies one of the many possible images, along with a report to combine the fragments appropriately.
Bruce Conrad bruce.conrad@utah.edu