General
The Image Server is a CGI-script that provides pictures in various dimensions.
Features
initial version
- request with arbitrary bounding box
- original picture ratio is maintained
- delivering and caching of pictures in dimensions of a certain raster
- picture fits into the requested bounding box and configured raster
- picture is just scaled down, never up
- serving scaled images per HTTP redirect to the location of an static image file
future versions
- support extern storage of scaled images to allow mirroring. (redirection map)
- support explicit precaching (to be copied to a mirror)
Design Decisions
Raster
We introduced a raster in which the images are scaled. This prevends the cache of get filled up with various fine grain scaled versions of the same image. The raster width is a configuration option which belongs to the caching group.
Specification
Behaviour
Request
A picture is requested with an picture name and a bounding box. The bounding box specifies the maximal size of the image. The Image Server has a configured raster in which it provides pictures. Lets assume the raster is set to 50 pixel. The picture size is scaled down to fit in the bounding box and then the width is rounded down multiple of 50. (The height is obviously scaled down as well) The needed version of the picture is looked up in the cache and is generated if needed. The file name contains the dimensions and the request is answered using redirection to that file. That allows browser side caching even for slightly different bounding boxes.
Raster
The raster with must be fixed over an reasonable lifetime of the server. The client shouldn't get different scaled images for the same requested dimension. In particular, the server is not allowed to serve a "good matching" version of an images which is a cache hit.
Cache
The cache is an important part of the Image Server since it can reduce the server side load and the latency time. The cache has a space limit and the caching stategy is LRU (least recently used).
Mirrors
A mirror should keep pictures in various sizes to save bandwidth or to gain faster access. It is also handy to be able to store the pictures on cheap webspace without CGI support. The Image Server has a mirror map where every mirror has a list of files it has. Furthermore there could be some information about the bandwith of the mirror. If a file is mirrored on more than one mirror is redirected with a probability ratio that correspond to the bandwith ratio.
Interface
CGI
The request URL is:
http://<host>/<path>/imgserv.cgi?src=<image src>&width=<width>&height=<height>
Where
<image src> is a complete URL or relative path identifier of the image to request. If the normal request URL of an image would be "images/1.jpg" than the
<image src> is "images/1.jpg" too.
<width> and
<height> are integers greater zero and denote the dimension of the requested image in pixel. Other units are not planed.
Examples:
http://<host>/<path>/imgserv.cgi?src=images/1.jpg&width=800&height=600
http://<host>/<path>/imgserv.cgi?src=http://<otherhost>/album1/slides/image1.jpg&width=800&height=600
Configuration
TODO: describe the configuration file syntax and options
Implementation
Raster
The dimension to serv is calculeted this way:
/*pseudo java code*/int calcWidth; //bounding box fitting width
int calcHeight; //bounding box fitting height
int servWidth; //width to serve
int servHeight; //height to serve
int raster; //width of the rasterservWidth = (calcWidth / raster) * raster; //integer division
servHeight = (calcHeight / raster) * raster;
This implementation as the problem, that the image ratio would not get kept. I suggest do applz the raster just on one of the dimensions.