diff options
| author | ChinCluBi <[email protected]> | 2016-08-12 14:21:05 +0700 |
|---|---|---|
| committer | ChinCluBi <[email protected]> | 2016-08-12 14:21:05 +0700 |
| commit | bc8ee47acecf2045f9bb4a504cd8494b8a7113e9 (patch) | |
| tree | f53fc28c59a44a82e234c13724854a9d3fe953ef /lib | |
| parent | ec13e84dcd6e01f908aa89bc56d3f8b1d5c9cd42 (diff) | |
| download | faker-bc8ee47acecf2045f9bb4a504cd8494b8a7113e9.tar.xz faker-bc8ee47acecf2045f9bb4a504cd8494b8a7113e9.zip | |
move random image from lorempixel.com to unsplash.com
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/image.js | 60 |
1 files changed, 53 insertions, 7 deletions
diff --git a/lib/image.js b/lib/image.js index 20576d92..ef4c12da 100644 --- a/lib/image.js +++ b/lib/image.js @@ -5,6 +5,8 @@ var Image = function (faker) { var self = this; + var otherCategories = ["abstract", "animals", "business", "cats", "city", "nightlife", "fashion", "sports", "technics", "transport"]; + var unsplashCategories = ["food", "nature", "people", "technology", "objects", "buildings"]; /** * image @@ -15,8 +17,8 @@ var Image = function (faker) { * @method faker.image.image */ self.image = function (width, height, randomize) { - var categories = ["abstract", "animals", "business", "cats", "city", "food", "nightlife", "fashion", "people", "nature", "sports", "technics", "transport"]; - return self[faker.random.arrayElement(categories)](width, height, randomize); + var allCategories = unsplashCategories.concat(otherCategories); + return self[faker.random.arrayElement(allCategories)](width, height, randomize); }; /** * avatar @@ -39,14 +41,25 @@ var Image = function (faker) { var width = width || 640; var height = height || 480; - var url ='http://lorempixel.com/' + width + '/' + height; - if (typeof category !== 'undefined') { - url += '/' + category; + var url ='https://source.unsplash.com'; + + if (typeof category !== 'undefined' && unsplashCategories.indexOf(category) > -1) { + url += '/category/' + category; + } + + url += '/' + width + 'x' + height + + if (typeof category !== 'undefined' && otherCategories.indexOf(category) > -1) { + url += '?' + category } + /* + Current version of unsplash official wrapper(source.unsplash.com) does not support full randomize yet. + I will implement randomize function with official unsplash api in next version. if (randomize) { url += '?' + faker.random.number() } + */ return url; }; @@ -192,7 +205,40 @@ var Image = function (faker) { */ self.transport = function (width, height, randomize) { return faker.image.imageUrl(width, height, 'transport', randomize); - } + }; + /** + * technology + * + * @param {number} width + * @param {number} height + * @param {boolean} randomize + * @method faker.image.technology + */ + self.technology = function (width, height, randomize) { + return faker.image.imageUrl(width, height, 'technology', randomize); + }; + /** + * objects + * + * @param {number} width + * @param {number} height + * @param {boolean} randomize + * @method faker.image.objects + */ + self.objects = function (width, height, randomize) { + return faker.image.imageUrl(width, height, 'objects', randomize); + }; + /** + * buildings + * + * @param {number} width + * @param {number} height + * @param {boolean} randomize + * @method faker.image.buildings + */ + self.buildings = function (width, height, randomize) { + return faker.image.imageUrl(width, height, 'buildings', randomize); + }; } -module["exports"] = Image;
\ No newline at end of file +module["exports"] = Image; |
