Image
Module to generate images.
Overview
For a random image, use url()
. This will not return the image directly but a URL pointing to an image from one of two demo image providers "Picsum" and "LoremFlickr". You can request an image specifically from one of two providers using urlLoremFlickr()
or urlPicsumPhotos()
.
For a random placeholder image containing only solid color and text, use urlPlaceholder()
(uses a third-party service) or dataUri()
(returns a SVG string).
For a random user avatar image, use avatar()
.
If you need more control over the content of the images, you can pass a category
parameter e.g. 'cat'
or 'nature'
to urlLoremFlickr()
or simply use faker.helpers.arrayElement()
with your own array of image URLs.
avatar
Generates a random avatar image url.
Available since v2.0.1
Returns: string
function avatar(): string;
Examples
faker.image.avatar() // 'https://avatars.githubusercontent.com/u/54881350'
Source
avatarGitHub
Generates a random avatar from GitHub.
Available since v8.0.0
Returns: string
function avatarGitHub(): string;
Examples
faker.image.avatarGitHub() // 'https://avatars.githubusercontent.com/u/54881350'
Source
avatarLegacy
Deprecated
This method is deprecated and will be removed in a future version.
The links are no longer working. Use avatar()
instead.
Generates a random avatar from https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar
.
Available since v8.0.0
Returns: string
function avatarLegacy(): string;
Examples
faker.image.avatarLegacy() // 'https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/686.jpg'
Source
dataUri
Generates a random data uri containing an URL-encoded SVG image or a Base64-encoded SVG image.
Available since v4.0.0
Parameters
Name | Type | Default | Description |
---|---|---|---|
options | { ... } | {} | Options for generating a data uri. |
options.color? | string | faker.color.rgb() | The color of the image. Must be a color supported by svg. |
options.height? | number | faker.number.int({ min: 1, max: 3999 }) | The height of the image. |
options.type? | 'svg-uri' | 'svg-base64' | faker.helpers.arrayElement(['svg-uri', 'svg-base64']) | The type of the image to return. Consisting of the file extension and the used encoding. |
options.width? | number | faker.number.int({ min: 1, max: 3999 }) | The width of the image. |
Returns: string
function dataUri(
options: {
width?: number;
height?: number;
color?: string;
type?: 'svg-uri' | 'svg-base64';
} = {}
): string;
Examples
faker.image.dataUri() // 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZlcnNpb249IjEuMSIgYmFzZVByb2ZpbGU9ImZ1bGwiIHdpZHRoPSIyMTk1IiBoZWlnaHQ9IjI4NjEiPjxyZWN0IHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9IiNkYjllOWQiLz48dGV4dCB4PSIxMDk3LjUiIHk9IjE0MzAuNSIgZm9udC1zaXplPSIyMCIgYWxpZ25tZW50LWJhc2VsaW5lPSJtaWRkbGUiIHRleHQtYW5jaG9yPSJtaWRkbGUiIGZpbGw9IndoaXRlIj4yMTk1eDI4NjE8L3RleHQ+PC9zdmc+'
faker.image.dataUri({ type: 'svg-base64' }) // 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZlcnNpb249IjEuMSIgYmFzZVByb2ZpbGU9ImZ1bGwiIHdpZHRoPSIxNTM0IiBoZWlnaHQ9IjMxNjciPjxyZWN0IHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9IiNiY2UxMTAiLz48dGV4dCB4PSI3NjciIHk9IjE1ODMuNSIgZm9udC1zaXplPSIyMCIgYWxpZ25tZW50LWJhc2VsaW5lPSJtaWRkbGUiIHRleHQtYW5jaG9yPSJtaWRkbGUiIGZpbGw9IndoaXRlIj4xNTM0eDMxNjc8L3RleHQ+PC9zdmc+'
Source
url
Generates a random image url.
Available since v8.0.0
Parameters
Name | Type | Default | Description |
---|---|---|---|
options | { ... } | {} | Options for generating a URL for an image. |
options.height? | number | faker.number.int({ min: 1, max: 3999 }) | The height of the image. |
options.width? | number | faker.number.int({ min: 1, max: 3999 }) | The width of the image. |
Returns: string
function url(
options: {
width?: number;
height?: number;
} = {}
): string;
Examples
faker.image.url() // 'https://picsum.photos/seed/qErTXnNw/2195/2861'
Source
urlLoremFlickr
Generates a random image url provided via https://loremflickr.com.
Available since v8.0.0
Parameters
Name | Type | Default | Description |
---|---|---|---|
options | { ... } | {} | Options for generating a URL for an image. |
options.category? | string | Category to use for the image. | |
options.height? | number | faker.number.int({ min: 1, max: 3999 }) | The height of the image. |
options.width? | number | faker.number.int({ min: 1, max: 3999 }) | The width of the image. |
Returns: string
function urlLoremFlickr(
options: {
width?: number;
height?: number;
category?: string;
} = {}
): string;
Examples
faker.image.urlLoremFlickr() // 'https://loremflickr.com/2195/2861?lock=5429209831737675'
faker.image.urlLoremFlickr({ width: 128 }) // 'https://loremflickr.com/128/2179?lock=3815943192872827'
faker.image.urlLoremFlickr({ height: 128 }) // 'https://loremflickr.com/2583/128?lock=3941435203169513'
faker.image.urlLoremFlickr({ category: 'nature' }) // 'https://loremflickr.com/3567/3854/nature?lock=3453734162604299'
Source
urlPicsumPhotos
Generates a random image url provided via https://picsum.photos.
Available since v8.0.0
Parameters
Name | Type | Default | Description |
---|---|---|---|
options | { ... } | {} | Options for generating a URL for an image. |
options.blur? | 0 | 10 | 2 | 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | faker.number.int({ max: 10 }) | Whether the image should be blurred. |
options.grayscale? | boolean | faker.datatype.boolean() | Whether the image should be grayscale. |
options.height? | number | faker.number.int({ min: 1, max: 3999 }) | The height of the image. |
options.width? | number | faker.number.int({ min: 1, max: 3999 }) | The width of the image. |
Returns: string
function urlPicsumPhotos(
options: {
width?: number;
height?: number;
grayscale?: boolean;
blur?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;
} = {}
): string;
Examples
faker.image.urlPicsumPhotos() // 'https://picsum.photos/seed/ErTXnNw/2195/2861?blur=5'
faker.image.urlPicsumPhotos({ width: 128 }) // 'https://picsum.photos/seed/1PMRY/128/2272'
faker.image.urlPicsumPhotos({ height: 128 }) // 'https://picsum.photos/seed/D8Wwp/3196/128?grayscale&blur=8'
faker.image.urlPicsumPhotos({ grayscale: true }) // 'https://picsum.photos/seed/1CBCWGmr/1058/3097?grayscale&blur=5'
faker.image.urlPicsumPhotos({ blur: 4 }) // 'https://picsum.photos/seed/d7jmzrZ6c/2790/241?blur=4'
faker.image.urlPicsumPhotos({ blur: 4, grayscale: true }) // 'https://picsum.photos/seed/sf96E8/646/2612?grayscale&blur=4'
Source
urlPlaceholder
Deprecated
This method is deprecated and will be removed in a future version.
The service has bad uptime. Use faker.image.url()
or faker.image.dataUri()
instead.
Generates a random image url provided via https://via.placeholder.com/.
Available since v8.0.0
Parameters
Name | Type | Default | Description |
---|---|---|---|
options | { ... } | {} | Options for generating a URL for an image. |
options.backgroundColor? | string | faker.color.rgb({ format: 'hex', prefix: '' }) | The background color of the image. |
options.format? | 'gif' | 'jpeg' | 'jpg' | 'png' | 'webp' | faker.helpers.arrayElement(['gif', 'jpeg', 'jpg', 'png', 'webp']) | The format of the image. |
options.height? | number | faker.number.int({ min: 1, max: 3500 }) | The height of the image. |
options.text? | string | faker.lorem.words() | The text to display on the image. |
options.textColor? | string | faker.color.rgb({ format: 'hex', prefix: '' }) | The text color of the image. |
options.width? | number | faker.number.int({ min: 1, max: 3500 }) | The width of the image. |
Returns: string
function urlPlaceholder(
options: {
width?: number;
height?: number;
backgroundColor?: string;
textColor?: string;
format?: 'gif' | 'jpeg' | 'jpg' | 'png' | 'webp';
text?: string;
} = {}
): string;
Examples
faker.image.urlPlaceholder() // 'https://via.placeholder.com/1921x2504/db9e9d/f8bbce.gif?text=alias%20accusator%20tristis'
faker.image.urlPlaceholder({ width: 128 }) // 'https://via.placeholder.com/128x2724/dfbab2/e3eb95.png?text=defleo%20minus%20accusamus'
faker.image.urlPlaceholder({ height: 128 }) // 'https://via.placeholder.com/2162x128/ddef79/f1ee42.jpeg?text=convoco%20molestiae%20decens'
faker.image.urlPlaceholder({ backgroundColor: '000000' }) // 'https://via.placeholder.com/3460x358/000000/43e5a5.gif?text=amor%20sollicito%20aptus'
faker.image.urlPlaceholder({ textColor: '000000' }) // 'https://via.placeholder.com/689x1291/c2c2fa/000000.webp?text=pecco%20tactus%20adflicto'
faker.image.urlPlaceholder({ format: 'png' }) // 'https://via.placeholder.com/990x421/62691f/c5b2ce.png?text=comis%20sopor%20apostolus'
faker.image.urlPlaceholder({ text: 'lorem ipsum' }) // 'https://via.placeholder.com/2508x1013/4c0c0e/5af5cd.jpg?text=lorem%20ipsum'
faker.image.urlPlaceholder({ width: 128, height: 128, backgroundColor: '000000', textColor: 'FF0000', format: 'png', text: 'lorem ipsum' }) // 'https://via.placeholder.com/128x128/000000/FF0000.png?text=lorem%20ipsum'