[Up]: Storage API : Image Converter

Image Converter

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

Description:  Resizes an image by percentage or pixel width & height and outputs to a file or stdout.  (This API does not manage cached images. If many small or thumbnail images are required, it is recommended to use tn.cgi instead.)

INPUT (via GET or POST)

   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
- only accepting image files with extension gif | jpg | jpeg | png | tif | tiff (case-insensitive)

tpath - the target file
- full storage path is expected here.
- (can be same as source, and thus will OVERWRITE it! Be careful.).
- the file extension of the target file is one of ( gif | jpg | jpeg | png | tif | tiff ) only (case-insensitive)
- conversion of image format will be done if source extension differs from target extension

- If this parameter is obmitted, the return content is the image file content itself (i.e. standard-output)
and the sever http response content-type will be of the appropraite type, e.g. image/jpeg.


resize_width - NN integer, targeted image width in pixel
resize_height - NN integer, targeted image 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 paramter. 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.


resize_percent - NN integer, the targeted image will be resize by the percentage given, maintainig aspect-ratio.
- Can be more than 100, which means expanding the original image.


NOTE: resize_width and resize_height should not be use together with resize_percent.


stdout_fmt
- only applicable if tpath is NOT specified.
- one of ( gif | jpg | jpeg | png | tif | tiff ) means to output in this image format
- this parameter can be left out, meaning stdout image format will follow the source format

ofmt => json | jsonp

output the response in JSON object.
"json" for formatting with minimal white space, and
"jsonp" for pretty formatting for easier human readability.
By default, for compatibility with legacy calls, non-JSON response is produced.

 

OUTPUT

   In case of tpath is obmitted, i.e. the converted 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 tpath is specified, the output will be in Content-type: text/plain.
The first word will be 'true' for successful execution, and 'false' followed by error message, otherwise.

If tpath is given and JSON output is requested, a successful return looks like this,

{
"status" : true
}

while an error return looks like this,

{
"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.