A simple wrapper for picsum.photos.
Just install via npm:
npm install --save lorem-picsum
You can use require
const loremPicsum = require("lorem-picsum");
or import
import loremPicsum from "lorem-picsum";
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.
These are the examples given from the Lorem Picsum website.
// gets an image with a specific width and height:
// returns "https://picsum.photos/200/300"
loremPicsum({
width: 200,
height: 300
});
// get an square image:
// (returns "https://picsum.photos/200")
loremPicsum({
width: 200
});
// get a random image:
// (returns "https://picsum.photos/200/300/?random")
loremPicsum({
width: 200,
height: 300,
random: true
});
// get a grayscale image:
// (returns "https://picsum.photos/g/200/300")
loremPicsum({
width: 200,
height: 300,
grayscale: true
});
// get a specific image:
// (returns "https://picsum.photos/200/300/?image=0")
loremPicsum({
width: 200,
height: 300,
image: 0
});
// get a blurred image:
// (returns "https://picsum.photos/200/300/?blur")
loremPicsum({
width: 200,
height: 300,
blur: true
});
// get an image with the crop gravity set
// (returns "https://picsum.photos/200/300/?gravity=east")
loremPicsum({
width: 200,
height: 300,
gravity: "east"
});