dl
Version:
DreamLab Libs
214 lines (183 loc) • 5.61 kB
JavaScript
var Class = require("core").Class;
var OcdnFilesUrl = require('./OcdnFilesUrl.js').OcdnFilesUrl,
OcdnTransformation = require('./OcdnTransformation.js').OcdnTransformation;
var OcdnImagesUrl = function(){
this.Extends = OcdnFilesUrl;
this.initialize = function(key, url) {
if (arguments.length == 1) {
url = key;
key = undefined;
}
this.parent(key, url, true);
this.init(url);
};
this.init = function (url) {
if (url) {
this.parent(url);
this.parse(url);
} else {
this.setPlugin('images');
}
};
this.parse = function (url) {
this.parent(url);
this.setPlugin('images');
};
this._getShortAppId = function () {
var appId = this._appName.split('.');
var length = appId.length;
if (appId[length-3] == 'front' && length > 5) {
if (appId[0]=='www') {
return appId[1];
} else {
return appId[0];
}
} else {
return appId[length-3];
}
};
this.clearTransformations = function () {
this._transformations = [];
return this;
};
//
// T R A N S F O R M S
//
this.rotate = function (angle) {
this._transformations.push({
transformation: OcdnTransformation.Transformation.ROTATE,
params: [angle]
});
return this;
};
this.blur = function (amount) {
this._transformations.push({
transformation: OcdnTransformation.Transformation.BLUR,
params: [amount]
});
return this;
};
this.resize = function (width, height, scaleUp, scaleDown) {
width = width || 0;
height = height || 0;
if(typeof scaleUp == "undefined"){
scaleUp = true;
}
scaleUp = +(scaleUp>0);
if(typeof scaleDown == "undefined"){
scaleDown = true;
}
scaleDown = +(scaleDown>0);
if (!width && !height) {
throw "Ocdn Resize: at least one width and height";
}
this._transformations.push({
transformation: OcdnTransformation.Transformation.RESIZE,
params: [width, height, scaleUp, scaleDown]
});
return this;
};
this.crop = function (x, y, width, height) {
this._transformations.push({
transformation: OcdnTransformation.Transformation.CROP,
params: [x, y, width, height]
});
return this;
};
this.grayscale = function () {
this._transformations.push({
transformation: OcdnTransformation.Transformation.GRAYSCALE,
params: []
});
return this;
};
this.boundingBox = function (width, height) {
this._transformations.push({
transformation: OcdnTransformation.Transformation.BOUNDING_BOX,
params: [width, height]
});
return this;
};
this.resizeCropAuto = this.boundingBox;
this.qualityPreset = function (preset) {
this._transformations.push({
transformation: OcdnTransformation.Transformation.QUALITY_PRESET,
params: [preset]
});
return this;
};
this.setBackground = function (r, g, b, a) {
this._transformations.push({
transformation: OcdnTransformation.Transformation.SETBACKGROUND,
params: [r, g, b, a]
});
return this;
};
this.preserveAnimation = function () {
console.warn('core.ocdn.OcdnImagesUrl.preserveAnimation is obsolete!');
return this;
};
this.disableAnimation = function () {
this._transformations.push({
transformation: OcdnTransformation.Transformation.DISABLEANIMATION,
params: []
});
return this;
};
this.combine = function (name, ext, fit, anchor, operation) {
this._transformations.push({
transformation: OcdnTransformation.Transformation.COMBINE,
params: [
name,
ext,
fit != 0 ? 1 : 0,
anchor,
operation
]
});
return this;
};
};
OcdnImagesUrl = new Class(new OcdnImagesUrl());
OcdnImagesUrl.SUPPORTED_IMAGE_FORMATS = {
'jpg' : 0,
'png' : 1,
'bmp' : 2,
'tiff' : 3,
};
OcdnImagesUrl.COMBINE_OPERATIONS = {
'over' : 0,
'in' : 1,
'out' : 2,
'atop' : 3,
'xor' : 4,
'plus' : 5,
'minus' : 6,
'add' : 7,
'subtract' : 8,
'difference' : 9,
'divide' : 10,
'multiply' : 11,
'bumpmap' : 12,
'copy' : 13,
'copyRed' : 14,
'copyGreen' : 15,
'copyBlue' : 16,
'copyOpacity' : 17,
'copyCyan' : 18,
'copyMagenta' : 19,
'copyYellow' : 20,
'copyBlack' : 21,
};
OcdnImagesUrl.COMBINE_ANCHORS = {
'northWest' : 0,
'north' : 1,
'northEast' : 2,
'west' : 3,
'center' : 4,
'east' : 5,
'southWest' : 6,
'south' : 7,
'southEast' : 8,
};
exports.OcdnImagesUrl = OcdnImagesUrl;