lorem-picsum
v1.0.0
Published
A wrapper for https://picsum.photos/
Downloads
67
Readme
lorem-picsum
A simple wrapper for picsum.photos.
Installation:
Just install via npm:
npm install --save lorem-picsum
Usage:
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.
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"
loremPicsum({
width: 200,
height: 300
});
Square Image
// get an square image:
// (returns "https://picsum.photos/200")
loremPicsum({
width: 200
});
Random Image
// get a random image:
// (returns "https://picsum.photos/200/300/?random")
loremPicsum({
width: 200,
height: 300,
random: true
});
Grayscale Image
// get a grayscale image:
// (returns "https://picsum.photos/g/200/300")
loremPicsum({
width: 200,
height: 300,
grayscale: true
});
Specific Image
// get a specific image:
// (returns "https://picsum.photos/200/300/?image=0")
loremPicsum({
width: 200,
height: 300,
image: 0
});
Blurred Image
// get a blurred image:
// (returns "https://picsum.photos/200/300/?blur")
loremPicsum({
width: 200,
height: 300,
blur: true
});
Crop Gravity
// get an image with the crop gravity set
// (returns "https://picsum.photos/200/300/?gravity=east")
loremPicsum({
width: 200,
height: 300,
gravity: "east"
});