Generates dynamic shape (PNG) images, intended for (JSP) page decoration, like rounded corners, arrows etc.
The library JAR file (imageservlet-1.0.jar) must be added to the /WEB-INF/lib directory of your webapp WAR file.
The servlet must be defined in the web.xml file of your webapp WAR. The snippet
below shows the servlet definition and url mapping to /img/*.
<servlet>
<servlet-name>ImageServlet</servlet-name>
<servlet-class>com.ribomation.imageservlet.ImageServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ImageServlet</servlet-name>
<url-pattern>/img/*</url-pattern>
</servlet-mapping>
The servlet also accepts the init parameters listed below.
| Name | Mandatory | Description |
|---|---|---|
| configFile | no | Name of properties file (e.g. /WEB-INF/imageservlet.properties) with default values. |
| configData | no | Newline separated list key=value pairs, with default values. |
| shapeClasses | no | Comma separated list of shape classes to load into the shape factory. |
| colorDefs | no | Comma separated list of colorName=hexCode pairs to load into the color factory. |
Example configuration.
<servlet>
<servlet-name>ImageServlet</servlet-name>
<servlet-class>com.ribomation.imageservlet.ImageServlet</servlet-class>
<init-param>
<param-name>shapeClasses</param-name>
<param-value>com.whatever.shapes.FooShape,com.whatever.shapes.BarShape</param-value>
</init-param>
</servlet>
The image servlet is invoked from an ordinary IMG HTML tag, were the SRC attribute referrs to the servlet (url mapping) plus request parameters. The snippet below shows an example.
<img width="50" height="50" src="/YOUR-WEBAPP/img?shape=rhomb&color=red&bgcolor=silver&width=50&height=50">
The request parameters accepted are listed in the table below.
| Name | Mandatory | Default | Description |
|---|---|---|---|
| shape | no | rhomb | The shape to paint |
| width | no | 50 | Width in pixels of the image |
| height | no | 50 | Height in pixels of the image |
| color | no | red | Color of the image |
| bgcolor | no | silver | Background color of the image |
The built-in shapes are listed in the table below. However, it's easy to define new shape types,
or redefine an existing ditto. Just sub-class AbstractShape and then add a shapeClasses
init parameter to the servlet.
| Shape Name | Description |
|---|---|
| rect | Rectangle |
| oval | Circle or ellipse |
| rhomb | Rhomb |
| triangle_down | Triangle pointing down |
| triangle_left | Triangle pointing left |
| triangle_right | Triangle pointing right |
| triangle_up | Triangle pointing up |
| corner_round_top_left | Squared image with a quarter circle area in quadrant top-left |
| corner_round_top_right | Squared image with a quarter circle area in quadrant top-right |
| corner_round_bottom_left | Squared image with a quarter circle area in quadrant bottom-left |
| corner_round_bottom_right | Squared image with a quarter circle area in quadrant bottom-right |
| corner_slope_top_left | Squared image with a quarter sloped/diagonal area in quadrant top-left |
| corner_slope_top_right | Squared image with a quarter sloped/diagonal area in quadrant top-right |
| corner_slope_bottom_left | Squared image with a quarter sloped/diagonal area in quadrant bottom-left |
| corner_slope_bottom_right | Squared image with a quarter sloped/diagonal area in quadrant bottom-right |
A color name, might be one of the predefined colors listed in the table below or a web color HEX code, like 'FFEEDD'.
| Color Name | HEX Value |
|---|---|
| black | 000000 |
| white | FFFFFF |
| red | FF0000 |
| green | 00FF00 |
| blue | 0000FF |
| yellow | FFFF00 |
| orange | FFA500 |
| silver | C0C0C0 |
| gray | 808080 |
| maroon | 800000 |
| purple | 800080 |
| fuchsia | FF00FF |
| lime | 008000 |
| olive | 808000 |
| navy | 000080 |
| teal | 008080 |
| aqua | 00FFFF |
The distribution comes with a small demo WAR, were you can try out different settings and view the
generated image. The demo is also available online.
Click here to view the ImageServlet demo.