Draw text servlet ver. 1.2

    Java servlet lets you write some text over the existing image. So you can add on the fly some copyright notice to your images for example.

How to use it:

a) copy drawtextPackage.jar into WEB-INF/lib directory

b) describe Draw text servlet in your web.xml file. You can provide the following parameters:

dir - describes a directory for your image files
width - Optional parameter. Describes a width for the final image. By default the original width will be used.
height - Optional parameter. Describes a height for the final image. By default the original height will be used.
text - Optional parameter. Describes a text. Default value is (c) Coldbeans.
size - Optional parameter. Describes a font size. Default value is 12.
face - Optional parameter. Describes a font face. Default value is Arial.
color - Optional parameter. Describes a font color. Format is #RRGGBB. Default value is #000000 - black color.
x - Optional parameter. Describes a position for the text. Default value is 5.
y - Optional parameter. Describes a position for the text. Default value is size+5. Note: x=0 y=0 describes a top left corner.
expires - describes a caching time (in seconds) for the images (client side cache).

For example:


    <servlet>
     <servlet-name>DrawText</servlet-name>
     <servlet-class>com.jsos.image.DrawTextServlet</servlet-class>
     <init-param>
     <param-name>dir</param-name>
     <param-value>c:/orion/default-web-app/images</param-value>
     </init-param>
     <init-param>
     <param-name>width</param-name>
     <param-value>125</param-value>
     </init-param>
     <init-param>
     <param-name>height</param-name>
     <param-value>125</param-value>
     </init-param>
     <init-param>
     <param-name>text</param-name>
     <param-value>(c)My Company</param-value>
     </init-param>
    </servlet>

You can provide both width and height or just one of them. In this case the second dimension will be changed accordingly.

c) describe a mapping for this servlet in web.xml file
 


<servlet-mapping>
  <servlet-name>DrawText</servlet-name>
  <url-pattern>/servlet/DrawText</url-pattern>
</servlet-mapping>

and now you can use servlet in this form: http://your_host/servlet/DrawText?image_file. E.g.:
 


<img border="0" alt="Preview" src="http://host/servlet/ImageScale?bigfile.jpg"/>

for downloading:

servlet: drawtextPackage.jar  

 © Coldbeans Software     Comments?

See also JSOS - the largest collection of servlets and filters.

Also in Coldtags: