Homepagina van Peter Verthez

imc, the Image Compiler

Introduction

This program originated from a kind of contest started by my sysadmin at work. He wanted a program that would allow to generate web pages that show system information. But as HTML is not very flexible in the placement of graphics and text on a page, he wanted a program that would accept drawing commands from a file or standard input, and would generate a GIF image.

Of course this is not difficult: a lot of APIs exist to generate GIF files, but to use them you still have to know not only the graphical commands, but also the language in which the program has to be written. Moreover, it is not so straightforward to automatically generate the source code to a C or Perl program that should output the GIF file.

So I wrote a Perl program at home that would just need an input of graphical commands to generate the GIF file. That was gifc, which was later on released to the world (on August 30, 1998).

However, when Unisys was enforcing its GIF patent, the Internet was turning away from GIF images (remember the "Burn all GIFs" day at November 5, 1999). Therefore, from release 4.0 on, my program did not generate GIF images anymore, but PNG images. It was therefore renamed to imc , in anticipation of supporting more image types in the future.  In fact, starting from release 4.1, JPEG output is also supported.

Later, the patent storm cleared, and now imc again supports GIF images (starting from release 4.3).

Download

You can download imc here. You will of course need Perl (version 5.004 or better), but also the GD Perl module (version 1.22 or better), which can be downloaded at CPAN.  For JPEG in/output, you'll need version 1.26 or better of the GD Perl module. For GIF in/output, you'll need version 2.15 or better of the GD Perl module.

The current version, version 4.3, re-adds input and output of GIF files, and fixes some bugs.

See the NEWS file for general changes or the ChangeLog file for detailed changes.

The program has been tested on Linux and HP-UX 10.20. I assume it also runs on other Unix platforms (it's Perl!), the build procedure is standard autoconf/automake based.

The README file contained in the package describes how to build and install imc.

Comments and bug reports can be mailed to me. Please include the version number of imc if you report bugs.

General features

The reference manual with the commands is included in the package, but can also be viewed here.

Generally, the most important features are the following:

  • Does not need a display to run.
  • Can be run from the command line or as CGI script. In the latter case, the image is output to the browser (in PNG, GIF or JPEG format).
  • The size of the output image is automatically determined, no size has to be specified (although you can give a fixed size)
  • Coordinates are in pixels, only positive coordinates are visible. Angles are in integer degrees, no limitations (except the maximum integer limit). Colors can be specified in one of three formats, including X11 color (rgb) strings
  • A pre-processor can be applied on the input file first; simple arithmetic can be performed.
  • Supports commands for drawing lines, circles (filled or not), rectangles (filled or not), ellipses (filled or not), arcs and text. Images can also be imported. For text and images an alignment parameter is available, and text and images can be rotated over any angle and can also be mirrored.

Example

A very simple example is the following piechart.

The file 'piechart.imc', contained in the package (in the subdirectory 'examples'), contains the following lines:

BACKGROUND TRANSPARENT SIZE 300 200 TEXTALIGN center ELLIPSE 100 120 80 40 FILLED RECTANGLE 180 120 20 100 FILLED #define PIED(the_color) COLOR X11 the_color CLOSED FILLED X11 the_color #define ANGLE(percent) { percent / 100 * 360 } ARC 100 100 80 40 ANGLE(0) ANGLE(15) PIED(red) RECTANGLE 200 40 210 50 FILLED X11 red TEXTAT 220 45 "Choice A" ARC 100 100 80 40 ANGLE(15) ANGLE(45) PIED(blue) RECTANGLE 200 70 210 80 FILLED X11 blue TEXTAT 220 75 "Choice B" ARC 100 100 80 40 ANGLE(45) ANGLE(75) PIED(green) RECTANGLE 200 100 210 110 FILLED X11 green TEXTAT 220 105 "Choice C" ARC 100 100 80 40 ANGLE(75) ANGLE(80) PIED(brown) RECTANGLE 200 130 210 140 FILLED X11 brown TEXTAT 220 135 "Choice D" ARC 100 100 80 40 ANGLE(80) ANGLE(100) PIED(purple) RECTANGLE 200 160 210 170 FILLED X11 purple TEXTAT 220 165 "Choice E"

And this is the PNG file that is generated from it:

Resulting pie chart

Note: Some browsers do not render the transparency of PNG images correctly. Netscape 4.51 is one of them... If you would change the background color of this page to grey, the background of the PNG image above would still be white on those browsers, although it is defined as transparent ! Image viewers like GQview get it right, though. Be aware of this problem...

One thing that people might remark on 'imc' is the lack of control statements, but that is done deliberately to restrict the size of the program. Besides, the input files are meant to be generated by an other program, so the control flow will be in there.

In fact, it is not even necessary to apply the C pre-processor on the input file in this context, but the effort of adding that feature was very small, so I just did it.