Scripting Web Graphics
Creation of even the simplest graphical elements can be a tiresome experience without a prior background and training in visual design. Developers prefer working on the next application functionality than fiddle around with imaging tools. This article revisits some of the major issues faced by programmers with image manipulation and proposes a developer-friendly solution for the same.
Creation of even the simplest graphical elements can be a tiresome experience without a prior background and training in visual design. Most developers would rather work on the next application functionality than fiddle around with Photoshop and similar imaging tools. Usability and aesthetics are considered to be the prerogatives of Web designers as a distinct and separate group of professionals.
This article takes a closer look at some of the major issues faced by programmers with image manipulation and proposes a developer-friendly solution for the same.
The Problem with Image Editors
A common problem faced during image manipulation is the ability to define and repeat a set of operations on multiple images in a consistent manner with predictable outputs. The manipulation is more to do with the contents of the image (e.g. a change in the background color) rather than external characteristics (e.g. image size).
Nearly all image editors fail to deliver on the above-mentioned requirements. The root cause of such failure can be ascribed to the following three factors:
- Fuzzy Generation: Input devices for image editors typically include mouse, lightpen and digital scanners. Predictability of output is affected by non-deterministic factors like steadiness of hand in drawing/erasing and digital noise introduced during scanning.
- Change Quantification: Changes made to an image cannot be quantified or documented in an intuitive and reliable fashion. This affects repeatability while working across a set of images. The issue is also applicable for replicating a series of steps in creating a new image.
- Rollback: While most image editors provide mechanisms to undo image manipulations, such rollbacks are at best transient in nature. Changes made to an image are usually permanent once the image is saved to disk. The series of changes made to arrive at the final output are never captured or stored.
Instruction-Driven Imaging
Instruction-driven images are more popularly known as vector graphics. Rather than store information about each and every pixel within an image, the set of instructions that can be used to arrive at the final raster are stored as image content. These instructions usually define geometrical primitives such as points, lines, curves and polygons. Examples of vector graphics formats include windows metafile (WMF), Postscript and Scalable Vector Graphics (SVG) to name a few.
While instruction-driven imaging can never replace raster graphics in terms of visual details, they do extremely well for simpler graphical elements that can be constructed using basic shapes, shadings and patterns. They also help avoid to a great degree the issues associated with raster editing as outlined above.
Imaging using High-Level Programming Languages
Ask yourself as a programmer, what could be the best possible syntax for an instruction-driven approach to imaging? The typical answer would be:
"the same high-level programming language that is used to implement most of the application functionalities."
The advantages of using a high-level programming language for instruction-driven imaging are as follows:
- The developer is exempted from the nuances of learning the semantics of a new format.
- Proficiency with known language syntax is leveraged.
- The availability of high-level language features like looping, conditionals, operators and subroutine calls.
- Extremely dynamic images with visual content based on the latest application data.
PHP is one such high-level language that can create and manipulate image files in a variety of different formats, including GIF, PNG, JPG, WBMP and XPM. Even more convenient, PHP can output image streams directly to a browser.
Introducing Scripted Imaging
Scripted Imaging is a small Java component that is inspired by and serves as an alternative to the graphical output capabilities of PHP. The component runs on a Java/JEE platform the minimum dependency being the availability of a servlet container for deployment. The imaging instructions are defined using a Java-like syntax and stored in text files (one file per image) on the server-side. These files are interpreted at runtime to generate raster images that are streamed to Web browsers on remote desktops using HTTP.
Other features of scripted imaging include the following:
- Image generation and manipulation using standard AWT/Swing packages.
- Output image in multiple formats (JPEG, PNG and GIF).
- Supports palette transparency. The output is either a 8-bit PNG or a GIF image.
- Load arbitrary fonts and images from disk.
- Modifications to scripts loaded dynamically in a servlet environment (hot deployment).
- Has access to HTTP request parameters, session and servlet context attributes.
- Can be executed from the command line to pre-create raster images from scripts.
Future Possibilities
Using a scripting notation and environment to generate Web graphics has more ramifications than what is immediately apparent. Apart from the simple yet useful rounded-corner images, fancy dividers and background gradients, a lot of interesting widgets can be generated using this technique. Examples of such widgets include charting components (like bar and pie charts), topology maps and UML diagrams.
Since both PHP/GD and Scripted Imaging have access to all libraries and objects provided by the corresponding platforms, it becomes possible to directly associate external systems and services with image sources to generate dynamic output. As an illustration, consider a scripted image directly accessing an RDBMS using JDBC to retrieve data and render the same in a bar chart as the output raster image.
References
[1] Vector graphics and raster graphics definitions on Wikipedia.
[2] PHP: Image Functions from the PHP manual.
[3] Scripted Imaging project web on SourceForge.
[4] Scalable Vector Graphics (SVG) 1.1 Specifications.
[5] PostScript Language Reference, Third Edition published by Addison-Wesley (PDF format)
Nothing Found!
Why not submit your own content? Signup here.
-
XA Transaction - Solution for Transaction More Than One Database | By H4d1 | in Programming
Have you ever think that it's too difficult for making database transaction in two different places (or databases) ...
-
Javascript functions for : trim, right trim, left trim, no Apostrophe, is Empty , is Digit , VarChar To Number , is integer , check Is Zero , Get Que | By xxris | in Programming
Javascript functions for : trim, right trim, left trim, no Apostrophe, is Empty , is Digit , VarChar To Number , i...
-
How to access and use a Window's command line | By MaxwellPayne | in Programming
Learn about the Window's command line in DOS and how to use it....
-
How to Learn to Program Your Computer | By dsj8760 | in Programming
This article is about learning to program a computer. It is a general article giving tips on how to learn about pro...
-
Jailbroken iPhones get RickRolled | By explorer | in Programming
First iPhone worm, attacks via SSH and does the classic rick roll gag on the user....
-
Globe's Sexiest Girl | By indroneel | in Film,TV & radio
A set of pictures of Deepika Padukone, Shantipriya and the globe's sexiest girl...
-
The Best Time of My Life | By indroneel | in Motivational
Whenever you worry about where you are in life –- remember, you are where you are suppose to be right now. This i...
-
Anybody knows TED? | By indroneel | in Human Interest
No, this is not the guy next door. This is a convergence of Technology, Entertainment and Design. Read on to learn ...
-
The Last Page of the Internet | By indroneel | in General
Did you know that there is a last page to the Internet? Read on......
-
Mind What You Say | By indroneel | in Politics
On President Barrack Obama's slip in comparing his bowling abilities with the capabilities of the people participat...







Great job! Very well written article and easy to understand, specifically for a technical topic. :)