Home > Developer

Storage API : Image Thumbnail generator

Image Converter

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

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.
        All cached images will be used for a short period after creation time, and thereafter
        regenerated. Input parameter is available to tell the API to ignore cache.

INPUT (via GET only)

 This API uses the path info 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/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/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 much 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 fit 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.

OUTPUT 

 In case of success, the thumbnail image content is sent back directly (standard output),
the Content-type header will appropraite 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.