lorem-picsum
picsum.photos.
A simple wrapper forInstallation:
Just install via npm:
npm install --save lorem-picsum
Usage:
You can use require
const loremPicsum = ;
or import
;
depending on the version of JavaScript you are using.
The lorem-picsum
package exports a single function which takes an options object. The only required option is width
, all others are optional:
Possible options are:
width
(number)height
(number)image
(number)grayscale
(boolean)random
(boolean)blur
(boolean)gravity
(string, one of "east", "north", "south", "west" or "center")
Note: random
is ignored if image
is supplied.
Examples:
These are the examples given from the Lorem Picsum website.
Basic Image
// gets an image with a specific width and height:// returns "https://picsum.photos/200/300";
Square Image
// get an square image:// (returns "https://picsum.photos/200");
Random Image
// get a random image:// (returns "https://picsum.photos/200/300/?random");
Grayscale Image
// get a grayscale image:// (returns "https://picsum.photos/g/200/300");
Specific Image
// get a specific image:// (returns "https://picsum.photos/200/300/?image=0");
Blurred Image
// get a blurred image:// (returns "https://picsum.photos/200/300/?blur");
Crop Gravity
// get an image with the crop gravity set// (returns "https://picsum.photos/200/300/?gravity=east");