Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80669 views
1
/**
2
* Copyright 2013 Facebook, Inc.
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*/
16
/*jslint proto:true*/
17
18
var inherits = require('util').inherits;
19
var Resource = require('./Resource');
20
21
22
/**
23
* Resource for *.png, *.jpg, *.gif files
24
* @extends {Resource}
25
* @class
26
* @param {String} path path of the resource
27
*/
28
function Image(path) {
29
Resource.call(this, path);
30
this.id = null;
31
}
32
inherits(Image, Resource);
33
Image.__proto__ = Resource;
34
35
Image.prototype.width = 0;
36
Image.prototype.height = 0;
37
Image.prototype.type = 'Image';
38
Image.prototype.version = '0.1';
39
40
Image.fromObject = function(obj) {
41
var image = new Image(obj.path);
42
image.path = obj.path;
43
image.width = obj.width || 0;
44
image.height = obj.height || 0;
45
image.mtime = obj.mtime;
46
return image;
47
};
48
49
Image.prototype.toObject = function() {
50
var obj = {
51
path: this.path,
52
id: this.id,
53
type: this.type,
54
mtime: this.mtime
55
};
56
if (this.width) {
57
obj.width = this.width;
58
}
59
if (this.height) {
60
obj.height = this.height;
61
}
62
return obj;
63
};
64
65
66
module.exports = Image;
67
68