Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generating ImageBoss URLs with JavaScript
function mountImageBossUrl(src, { operation, cover_mode, width, height, options }) {
var serviceUrl = 'https://img.imageboss.me';
var template = '/:operation/:options/';
if (operation === 'cover') {
template = '/:operation::cover_mode/:widthx:height/:options/';
} else if (operation === 'width') {
template = '/:operation/:width/:options/';
} else if (operation === 'height') {
template = '/:operation/:height/:options/';
}
var finalUrl = template
.replace(':operation', operation || 'cdn')
.replace(':cover_mode', cover_mode || '')
.replace(':width', width || '')
.replace(':height', height || '')
.replace(':options', options || '')
.replace(/\/\//g, '/')
.replace(/:\//g, '/')
return serviceUrl + finalUrl + src;
}
var image = 'https://img.test.com/img.jpg';
console.log(mountImageBossUrl(image, {operation: 'cdn'}));
console.log(mountImageBossUrl(image, {operation: 'cover', width: 500, height: 500 }));
console.log(mountImageBossUrl(image, {operation: 'cover', cover_mode: 'face', width: 500, height: 500 }));
console.log(mountImageBossUrl(image, {operation: 'width', width: 500 }));
console.log(mountImageBossUrl(image, {operation: 'height', height: 500 }));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.