Created
November 29, 2012 14:16
-
-
Save uniqname/4169374 to your computer and use it in GitHub Desktop.
js function for exposure django app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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