Skip to content

Instantly share code, notes, and snippets.

@uniqname
Created November 29, 2012 14:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uniqname/4169374 to your computer and use it in GitHub Desktop.
Save uniqname/4169374 to your computer and use it in GitHub Desktop.
js function for exposure django app
exposure = function () {
/*
RETURNS: An exposure URL which returns the specified image resized to specified height and width
ARGUMENTS: object || url:string [, height:string||int] [, width:string||int]
The exposure method takes either an object or one or more strings as arguments.
A value of "0" for "width" or "height" indicates that exposure should use a value
that maintains the image's native aspect ratio.
USAGE:
exposure( { url: 'http://mydomain.com/path/to/image.jpg'[, width: #] [, height: #] } )
exposure( { url: 'http://mydomain.com/path/to/image.jpg', width: 100, height: 0 } )
If an object is passed, it must contain at least a "url" key with
it's value being the fully qualified URL of the image to be resized. Optionally,
"width" and "height" keys may also be included.
exposure( url, [width,] [height])
exposure( url, 600, 400)
If strings are passed, the only required argument is "url" which must be the fully
qualified url for the image that is to be resized.
*/
var url, width, height, errorMsg;
url = arguments[0];
width = arguments[1] || 0;
height = arguments[2] || 0;
errorMsg = 'exposure(): a fully qualified url for an image must be supplied';
if (url) {
if (url['url']) {
width = url['width'] || 0;
height = url['height'] || 0;
url = url['url'];
}
if (typeof url !== 'string') {
throw new Error(errorMsg);
} else {
return ['/exposure/transcode/', width, '/', height, '/?url=', url].join();
}
} else {
throw new Error(errorMsg);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment