Skip to content

Commit

Permalink
Merge pull request #855 from abnersajr/fix-797
Browse files Browse the repository at this point in the history
Adds Lorem Picsum as image provider
  • Loading branch information
Marak authored Aug 25, 2020
2 parents 95b1c09 + 8f4c832 commit 4644f37
Show file tree
Hide file tree
Showing 4 changed files with 8,331 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
* @namespace faker.image
* @property {object} lorempixel - faker.image.lorempixel
* @property {object} unsplash - faker.image.unsplash
* @property {object} unsplash - faker.image.lorempicsum
* @default Default provider is unsplash image provider
*/
var Image = function (faker) {

var self = this;
var Lorempixel = require('./image_providers/lorempixel');
var Unsplash = require('./image_providers/unsplash');
var LoremPicsum = require('./image_providers/lorempicsum');

/**
* image
Expand Down Expand Up @@ -218,6 +220,7 @@ var Image = function (faker) {

self.lorempixel = new Lorempixel(faker);
self.unsplash = new Unsplash(faker);
self.lorempicsum = new LoremPicsum(faker);

// Object.assign(self, self.unsplash);
// How to set default as unsplash? should be image.default?
Expand Down
108 changes: 108 additions & 0 deletions lib/image_providers/lorempicsum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/**
*
* @namespace lorempicsum
* @memberof faker.image
*/
var LoremPicsum = function (faker) {

var self = this;

/**
* image
*
* @param {number} width
* @param {number} height
* @param {boolean} grayscale
* @param {number} blur 1-10
* @method faker.image.lorempicsum.image
* @description search image from unsplash
*/
self.image = function (width, height, grayscale, blur) {
return self.imageUrl(width, height, grayscale, blur);
};
/**
* imageGrayscaled
*
* @param {number} width
* @param {number} height
* @param {boolean} grayscale
* @method faker.image.lorempicsum.imageGrayscaled
* @description search grayscale image from unsplash
*/
self.imageGrayscale = function (width, height, grayscale) {
return self.imageUrl(width, height, grayscale);
};
/**
* imageBlurred
*
* @param {number} width
* @param {number} height
* @param {number} blur 1-10
* @method faker.image.lorempicsum.imageBlurred
* @description search blurred image from unsplash
*/
self.imageBlurred = function (width, height, blur) {
return self.imageUrl(width, height, undefined, blur);
};
/**
* imageRandomSeeded
*
* @param {number} width
* @param {number} height
* @param {boolean} grayscale
* @param {number} blur 1-10
* @param {string} seed
* @method faker.image.lorempicsum.imageRandomSeeded
* @description search same random image from unsplash, based on a seed
*/
self.imageRandomSeeded = function (width, height, grayscale, blur, seed) {
return self.imageUrl(width, height, grayscale, blur, seed);
};
/**
* avatar
*
* @method faker.image.lorempicsum.avatar
*/
self.avatar = function () {
return faker.internet.avatar();
};
/**
* imageUrl
*
* @param {number} width
* @param {number} height
* @param {boolean} grayscale
* @param {number} blur 1-10
* @param {string} seed
* @method faker.image.lorempicsum.imageUrl
*/
self.imageUrl = function (width, height, grayscale, blur, seed) {
var width = width || 640;
var height = height || 480;

var url = 'https://picsum.photos';

if (seed) {
url += '/seed/' + seed;
}

url += '/' + width + '/' + height;

if (grayscale && blur) {
return url + '?grayscale' + '&blur=' + blur;
}

if (grayscale) {
return url + '?grayscale';
}

if (blur) {
return url + '?blur=' + blur;
}

return url;
};
}

module["exports"] = LoremPicsum;

Loading

0 comments on commit 4644f37

Please sign in to comment.