Image taglib ver. 2.0


    Custom JSP taglib. Tag convertImage lets you proceed images. You can scale them to the given width and height, as well as rotate them.

Taglib uses free open source library ImageJ for image processing. You have to download the latest ij.jar file right from ImageJ home page and save it in WEB-INF/lib directory.

For example:
 


<%@ taglib uri="taglib.tld" prefix="im" %>

<im:convertImage sourceFile="c:/pictures/picture.jpg" targetFile="c:/pictures/picture125x125.jpg" width="125" height="125"/>

when you need to convert many files in your server side code you can combine convertImage tags into some package (in order to save memory):
 


<%@ taglib uri="taglib.tld" prefix="im" %>

<im:batchProcessing>
 <im:convertImage sourceFile="c:/pictures/picture1.jpg" targetFile="c:/pictures/picture1-125x125.jpg" width="125" height="125"/>
 <im:convertImage sourceFile="c:/pictures/picture2.jpg" targetFile="c:/pictures/picture2-125x125.jpg" width="125" height="125"/>
 ...
</im:batchProcessing>

Tag cropImage lets you extract a part of the given image. You can provide either coordinates for the top left corner (x,y) and (width,heght) or (width,height) only. In this case the extracted image will be centered (top left corner's coordinates will be calculated automatically).

Why do we include this taglib into our suite? As we see, that it is a very common task when developers need to convert uploaded images or scale them depends on user's agent. We hope this taglib helps them with such tasks.

Tags are:

convertImage

Converts image: scales it according to the given width and height, rotates it and saves in the new file or streams to the browser. Parameters are:

1) sourceFile Optional parameter. Describes a path to source file (tiff, jpg, gif, png)
2) sourceUrl Optional parameter. Describes an URL for your source file (tiff, jpg, gif, png)
3) targetFile Optional parameter. Describes a path to target file. By default tag streams converted image to the browser
4) width Optional parameter. Describes a width for the converted image (in pixels).
5) height Optional parameter. Describes a height for the converted image (in pixels).
6) keepRatio Optional parameter. Possible values are true or false. If this value is true you can define only one new size (width or height) and the second one will be calculated automatically to keep aspect ration. Default value is false.
7) angle Optional parameter. Describes an angle for rotation (clockwise, in grads).
8) interpolate Optional parameter. Possible values are true or false. True values here sets a nonlinear interpolation. Default value is false.
9) overwrite Optional parameter. Possible values are true or false. If this value is true then the existing target file will be overwritten. Default value is true.

cropImage

Crops image: extracts part of it according to the given width and height, rotates it and saves in the new file or streams to the browser. Parameters are:

1) sourceFile Optional parameter. Describes a path to source file (tiff, jpg, gif, png)
2) sourceUrl Optional parameter. Describes an URL for your source file (tiff, jpg, gif, png)
3) targetFile Optional parameter. Describes a path to target file. By default tag streams converted image to the browser
4) x Optional parameter. Describes a top left corner.
5) y Optional parameter. Describes a top left corner.
6) width Describes a width for the converted image (in pixels).
7) height Describes a height for the converted image (in pixels).
8) angle Optional parameter. Describes an angle for rotation (clockwise, in grads).
9) overwrite Optional parameter. Possible values are true or false. If this value is true then the existing target file will be overwritten. Default value is true.

getSize

Retrieves width and height for the image. Parameters are:

1) sourceFile Optional parameter. Describes a path to source file (jpg, gif, png)
2) sourceUrl Optional parameter. Describes an URL for your source file (tiff, jpg, gif, png)
3) idWidth Describes a name for page scope varible (type is java.lang.Integer) for width.
4) idHeight Describes a name for page scope varible (type is java.lang.Integer) for height.

batchProcessing

Body tag allows you to execute several convertImage tags in the one package. Parameters are: none

for downloading:

Library: imagetag.jar    Description: taglib.tld

© Coldbeans      Comments?

See also Coldtags suite - the largest collection of custom JSP tags.

Also in Coldtags: