-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage.js
More file actions
44 lines (41 loc) · 1.28 KB
/
image.js
File metadata and controls
44 lines (41 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* Class to create a Image object
*/
class Image {
/**
* @param {String} _imageUri path of image
* @param {String} _cloudName cloud name
* @param {String} _zone cloud zone
* @param {Boolean} _worker enable/disable url translation worker
*/
constructor(_imageUri, _cloudName, _zone, _worker) {
this.imageUri = _imageUri;
this.cloudName = _cloudName;
this.zone = _zone;
this.transformation = [];
this.host = "https://cdn.pixelbin.io";
this.version = "v2";
this.worker = _worker;
}
/**
* Set transformation to be performed on the Image.
* @param {import('./transformation.js').default} transformation - Image transformation.
* @returns {Image}
*/
setTransformation(transformation) {
this.transformation = transformation.getTransformation();
return this;
}
/**
* Get Transformation CDN link.
* @returns {String}
*/
getUrl() {
let operations = this.transformation.join("~").replace(/ /g, "") || "original";
if (this.worker) operations = "wrkr";
return `${this.host}/${this.version}/${this.cloudName}/${
this.zone ? `${this.zone}/` : ""
}${operations}/${this.imageUri}`;
}
}
export default Image;