[Up]: Storage API : Image Thumbnail generator

Image Converter

Script path: /storage/bin/api/tn.cgi

Description:  Description: Generates a thumbnail version of image of pixel width and/or height and outputs to stdout.
        It will also transparently cache the thumbnail under _thumb subdirectory, to improve performance.
        By default all cached images will be used as long as its timestamp is newer than original image file.
        Input parameter is available to tell the API to ignore cache, immediately or after a given time period.
        Different sets of cached images, perhaps for different sized thumbnails, can be managed.  

INPUT (via GET method only)

   This API uses the path info in the submitted URL to receive input parameters in order to have better result in browser.

http://hostname/storage/bin/api/tn.cgi/[sid]/[-opts]+/[path]

The sid, -opts and path forms the parameters to this API.

For Example,
http://hostname/storage/bin/api/tn.cgi/SIDxxxxxxxxxxxx/-w64-j/Private/subfolder/myImage.jpg
http://hostname/storage/bin/api/tn.cgi/SIDxxxxxxxxxxxx/-w64-h100-s1/Private/subfolder/myImage.jpg
http://hostname/storage/bin/api/tn.cgi/SIDxxxxxxxxxxxx/-h100-c0-j/Private/subfolder/myImage.jpg

sid - the user's SID (mandatory)

path - the source file (mandatory)
- full storage path to the file is expected. e.g. /Private/myalbum/pic-002.jpg
- while these image file can be handled, gif | jpg | jpeg |jpe | png | tif | tiff (case-insensitive),
others may not necessarily work.

-opts (mandatory, at least one option below)

This is an embeded way of sending parameters to the API. The order of the parameters is irrelevant,
but each must be preceded by a dash '-'. At least one opt should be specified.

'-wNN' where NN is integer, specifies the thumnail width in pixel
'-hNN' where NN is integer, specifies the thumnail height in pixel

NOTE: these 2 parameters can be specified individually or together, with differing meaning in each case.

When only ONE of these parameter is specified, the original image's width/height will be shrinked to
match the specified parameter. The original aspect-ratio will be perserved in the resulting image.
This case does NOT expand the original image if the original image width/height is smaller than
the value specified here.

When BOTH parameters are specified, the original image will be shrink or expand to fix EXACTLY the
specified dimension. Aspect-ratio thus may be changed and expansion of an image is possible.


'-cMMM' to tell the API the acceptable lifespan of a cached thumbnail, in minutes.
If an existing thumbnail is older that MMM mins, it will be ignored, and new thumbnail generated
e.g. '-c30' means 30 mins lifespan.
'-c0' will guarantee generation of new thumbnail, i.e. ignores any cached copy immediately.

If this option is obmitted, the default is INDETERMINED lifespan, as long as thumbnail file date
is *newer* than the original file's timestamp.

'-s?' to tell the API which set of cached thumbnails to store. This option allow you to have
different sets of thumbnails of different sizes, perhaps. But it is your responsibility to manage
which set. The sets are differentiated by the single ascii character '?' in the option, and it range
from 0,1,2,...9,a,b,c,...z. e.g. -s1 means set 1, -s2 means set 2, etc.
By default, i.e. if -s is not given, it will assumed to be set 0.

'-j' to tell the API to ouput HTTP content in JSON pretty format in case of error
conditions (HTTP status not= OK 200). If this option is omitted, legacy "flat" formatted
content will be returned.


OUTPUT 

   In case of success, the thumbnail image content is sent back directly (standard output),
the Content-type header will appropriate to the image content type returned, and the entire response
content is the image content itself.

In case of error, the output will be in Content-type: text/plain.
The first word will be 'false' followed by error message.
Example,

false Item does not exist.

Optionally, in case of error, a JSON formatted output will indicate the condition and error message.
Example,

{
"http_status" : "404 Item does not exist",
"status" : false,
"errmsg" : "Item does not exist."
}

Appropriate HTTP header status codes are also returned e.g. 200 OK, 401 Invalid user profile, etc.