Skip to content
On this page

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 urlPicsum().

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().

This module previously also contained methods for specifically themed images like "fashion" or "food", but these are now deprecated. If you need more control over image type, you are recommended to use an image provider directly or provide your own set of placeholder images.

abstract

Deprecated

This method is deprecated and will be removed in a future version.

Use faker.image.url instead.

Generates a random abstract image url.

Available since v2.0.1

Parameters

NameTypeDefaultDescription
width?number640

The width of the image.

height?number480

The height of the image.

randomize?booleanfalse

Whether to randomize the image or not.

Returns: string

ts
faker.image.abstract(width?: number = 640, height?: number = 480, randomize?: boolean = false): string
faker.image.abstract() // => "https://loremflickr.com/640/480/abstract"
faker.image.abstract() // 'https://loremflickr.com/640/480/abstract'
faker.image.abstract(1234, 2345) // 'https://loremflickr.com/1234/2345/abstract'
faker.image.abstract(1234, 2345, true) // 'https://loremflickr.com/1234/2345/abstract?lock=56789'

animals

Deprecated

This method is deprecated and will be removed in a future version.

Use faker.image.url instead.

Generates a random animal image url.

Available since v2.0.1

Parameters

NameTypeDefaultDescription
width?number640

The width of the image.

height?number480

The height of the image.

randomize?booleanfalse

Whether to randomize the image or not.

Returns: string

ts
faker.image.animals(width?: number = 640, height?: number = 480, randomize?: boolean = false): string
faker.image.animals() // => "https://loremflickr.com/640/480/animals"
faker.image.animals() // 'https://loremflickr.com/640/480/animals'
faker.image.animals(1234, 2345) // 'https://loremflickr.com/1234/2345/animals'
faker.image.animals(1234, 2345, true) // 'https://loremflickr.com/1234/2345/animals?lock=56789'

avatar

Generates a random avatar image url.

Available since v2.0.1

Returns: string

ts
faker.image.avatar(): string
faker.image.avatar() // => "https://avatars.githubusercontent.com/u/59284462"
faker.image.avatar()
// 'https://avatars.githubusercontent.com/u/97165289'

avatarGitHub

Generates a random avatar from GitHub.

Available since v8.0.0

Returns: string

ts
faker.image.avatarGitHub(): string
faker.image.avatarGitHub() // => "https://avatars.githubusercontent.com/u/54881350"
faker.image.avatarGitHub()
// 'https://avatars.githubusercontent.com/u/97165289'

avatarLegacy

Generates a random avatar from https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar.

Available since v8.0.0

Returns: string

ts
faker.image.avatarLegacy(): string
faker.image.avatarLegacy() // => "https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHir...
faker.image.avatarLegacy()
// 'https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/170.jpg'

business

Deprecated

This method is deprecated and will be removed in a future version.

Use faker.image.url instead.

Generates a random business image url.

Available since v2.0.1

Parameters

NameTypeDefaultDescription
width?number640

The width of the image.

height?number480

The height of the image.

randomize?booleanfalse

Whether to randomize the image or not.

Returns: string

ts
faker.image.business(width?: number = 640, height?: number = 480, randomize?: boolean = false): string
faker.image.business() // => "https://loremflickr.com/640/480/business"
faker.image.business() // 'https://loremflickr.com/640/480/business'
faker.image.business(1234, 2345) // 'https://loremflickr.com/1234/2345/business'
faker.image.business(1234, 2345, true) // 'https://loremflickr.com/1234/2345/business?lock=56789'

cats

Deprecated

This method is deprecated and will be removed in a future version.

Use faker.image.url instead.

Generates a random cat image url.

Available since v2.0.1

Parameters

NameTypeDefaultDescription
width?number640

The width of the image.

height?number480

The height of the image.

randomize?booleanfalse

Whether to randomize the image or not.

Returns: string

ts
faker.image.cats(width?: number = 640, height?: number = 480, randomize?: boolean = false): string
faker.image.cats() // => "https://loremflickr.com/640/480/cats"
faker.image.cats() // 'https://loremflickr.com/640/480/cats'
faker.image.cats(1234, 2345) // 'https://loremflickr.com/1234/2345/cats'
faker.image.cats(1234, 2345, true) // 'https://loremflickr.com/1234/2345/cats?lock=56789'

city

Deprecated

This method is deprecated and will be removed in a future version.

Use faker.image.url instead.

Generates a random city image url.

Available since v2.0.1

Parameters

NameTypeDefaultDescription
width?number640

The width of the image.

height?number480

The height of the image.

randomize?booleanfalse

Whether to randomize the image or not.

Returns: string

ts
faker.image.city(width?: number = 640, height?: number = 480, randomize?: boolean = false): string
faker.image.city() // => "https://loremflickr.com/640/480/city"
faker.image.city() // 'https://loremflickr.com/640/480/city'
faker.image.city(1234, 2345) // 'https://loremflickr.com/1234/2345/city'
faker.image.city(1234, 2345, true) // 'https://loremflickr.com/1234/2345/city?lock=56789'

dataUri

Generates a random data uri containing an svg image.

Available since v4.0.0

Parameters

NameTypeDefaultDescription
options{ ... }{}

Options for generating a data uri.

options.color?string'grey'

The color of the image.

options.height?number480

The height of the image.

options.width?number640

The width of the image.

Returns: string

ts
faker.image.dataUri(options: {
  color: string,
  height: number,
  width: number
} = {}): string
faker.image.dataUri() // => "data:image/svg+xml;charset=UTF-8,%3Csvg%20xmln...
faker.image.dataUri() // 'data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http...'

fashion

Deprecated

This method is deprecated and will be removed in a future version.

Use faker.image.url instead.

Generates a random fashion image url.

Available since v2.0.1

Parameters

NameTypeDefaultDescription
width?number640

The width of the image.

height?number480

The height of the image.

randomize?booleanfalse

Whether to randomize the image or not.

Returns: string

ts
faker.image.fashion(width?: number = 640, height?: number = 480, randomize?: boolean = false): string
faker.image.fashion() // => "https://loremflickr.com/640/480/fashion"
faker.image.fashion() // 'https://loremflickr.com/640/480/fashion'
faker.image.fashion(1234, 2345) // 'https://loremflickr.com/1234/2345/fashion'
faker.image.fashion(1234, 2345, true) // 'https://loremflickr.com/1234/2345/fashion?lock=56789'

food

Deprecated

This method is deprecated and will be removed in a future version.

Use faker.image.url instead.

Generates a random food image url.

Available since v2.0.1

Parameters

NameTypeDefaultDescription
width?number640

The width of the image.

height?number480

The height of the image.

randomize?booleanfalse

Whether to randomize the image or not.

Returns: string

ts
faker.image.food(width?: number = 640, height?: number = 480, randomize?: boolean = false): string
faker.image.food() // => "https://loremflickr.com/640/480/food"
faker.image.food() // 'https://loremflickr.com/640/480/food'
faker.image.food(1234, 2345) // 'https://loremflickr.com/1234/2345/food'
faker.image.food(1234, 2345, true) // 'https://loremflickr.com/1234/2345/food?lock=56789'

image

Deprecated

This method is deprecated and will be removed in a future version.

Use faker.image.url instead.

Generates a random image url from one of the supported categories.

Available since v2.0.1

Parameters

NameTypeDefaultDescription
width?number640

The width of the image.

height?number480

The height of the image.

randomize?booleanfalse

Whether to randomize the image or not.

Returns: string

ts
faker.image.image(width?: number = 640, height?: number = 480, randomize?: boolean = false): string
faker.image.image() // => "https://loremflickr.com/640/480/fashion"
faker.image.image() // 'https://loremflickr.com/640/480/city'
faker.image.image(1234, 2345) // 'https://loremflickr.com/1234/2345/sports'
faker.image.image(1234, 2345, true) // 'https://loremflickr.com/1234/2345/nature?lock=56789'

imageUrl

Deprecated

This method is deprecated and will be removed in a future version.

Use faker.image.url instead.

Generates a random image url.

Available since v2.0.1

Parameters

NameTypeDefaultDescription
width?number640

The width of the image.

height?number480

The height of the image.

category?string

The category of the image. By default, a random one will be selected.

randomize?booleanfalse

Whether to randomize the image or not.

Returns: string

ts
faker.image.imageUrl(width?: number = 640, height?: number = 480, category?: string, randomize?: boolean = false): string
faker.image.imageUrl() // => "https://loremflickr.com/640/480"
faker.image.imageUrl() // 'https://loremflickr.com/640/480'
faker.image.imageUrl(1234, 2345) // 'https://loremflickr.com/1234/2345'
faker.image.imageUrl(1234, 2345, 'cat') // 'https://loremflickr.com/1234/2345/cat'
faker.image.imageUrl(1234, 2345, 'cat', true) // 'https://loremflickr.com/1234/2345/cat?lock=6849'

nature

Deprecated

This method is deprecated and will be removed in a future version.

Use faker.image.url instead.

Generates a random nature image url.

Available since v2.0.1

Parameters

NameTypeDefaultDescription
width?number640

The width of the image.

height?number480

The height of the image.

randomize?booleanfalse

Whether to randomize the image or not.

Returns: string

ts
faker.image.nature(width?: number = 640, height?: number = 480, randomize?: boolean = false): string
faker.image.nature() // => "https://loremflickr.com/640/480/nature"
faker.image.nature() // 'https://loremflickr.com/640/480/nature'
faker.image.nature(1234, 2345) // 'https://loremflickr.com/1234/2345/nature'
faker.image.nature(1234, 2345, true) // 'https://loremflickr.com/1234/2345/nature?lock=56789'

nightlife

Deprecated

This method is deprecated and will be removed in a future version.

Use faker.image.url instead.

Generates a random nightlife image url.

Available since v2.0.1

Parameters

NameTypeDefaultDescription
width?number640

The width of the image.

height?number480

The height of the image.

randomize?booleanfalse

Whether to randomize the image or not.

Returns: string

ts
faker.image.nightlife(width?: number = 640, height?: number = 480, randomize?: boolean = false): string
faker.image.nightlife() // => "https://loremflickr.com/640/480/nightlife"
faker.image.nightlife() // 'https://loremflickr.com/640/480/nightlife'
faker.image.nightlife(1234, 2345) // 'https://loremflickr.com/1234/2345/nightlife'
faker.image.nightlife(1234, 2345, true) // 'https://loremflickr.com/1234/2345/nightlife?lock=56789'

people

Deprecated

This method is deprecated and will be removed in a future version.

Use faker.image.url instead.

Generates a random people image url.

Available since v2.0.1

Parameters

NameTypeDefaultDescription
width?number640

The width of the image.

height?number480

The height of the image.

randomize?booleanfalse

Whether to randomize the image or not.

Returns: string

ts
faker.image.people(width?: number = 640, height?: number = 480, randomize?: boolean = false): string
faker.image.people() // => "https://loremflickr.com/640/480/people"
faker.image.people() // 'https://loremflickr.com/640/480/people'
faker.image.people(1234, 2345) // 'https://loremflickr.com/1234/2345/people'
faker.image.people(1234, 2345, true) // 'https://loremflickr.com/1234/2345/people?lock=56789'

sports

Deprecated

This method is deprecated and will be removed in a future version.

Use faker.image.url instead.

Generates a random sports image url.

Available since v2.0.1

Parameters

NameTypeDefaultDescription
width?number640

The width of the image.

height?number480

The height of the image.

randomize?booleanfalse

Whether to randomize the image or not.

Returns: string

ts
faker.image.sports(width?: number = 640, height?: number = 480, randomize?: boolean = false): string
faker.image.sports() // => "https://loremflickr.com/640/480/sports"
faker.image.sports() // 'https://loremflickr.com/640/480/sports'
faker.image.sports(1234, 2345) // 'https://loremflickr.com/1234/2345/sports'
faker.image.sports(1234, 2345, true) // 'https://loremflickr.com/1234/2345/sports?lock=56789'

technics

Deprecated

This method is deprecated and will be removed in a future version.

Use faker.image.url instead.

Generates a random technics image url.

Available since v2.0.1

Parameters

NameTypeDefaultDescription
width?number640

The width of the image.

height?number480

The height of the image.

randomize?booleanfalse

Whether to randomize the image or not.

Returns: string

ts
faker.image.technics(width?: number = 640, height?: number = 480, randomize?: boolean = false): string
faker.image.technics() // => "https://loremflickr.com/640/480/technics"
faker.image.technics() // 'https://loremflickr.com/640/480/technics'
faker.image.technics(1234, 2345) // 'https://loremflickr.com/1234/2345/technics'
faker.image.technics(1234, 2345, true) // 'https://loremflickr.com/1234/2345/technics?lock=56789'

transport

Deprecated

This method is deprecated and will be removed in a future version.

Use faker.image.url instead.

Generates a random transport image url.

Available since v2.0.1

Parameters

NameTypeDefaultDescription
width?number640

The width of the image.

height?number480

The height of the image.

randomize?booleanfalse

Whether to randomize the image or not.

Returns: string

ts
faker.image.transport(width?: number = 640, height?: number = 480, randomize?: boolean = false): string
faker.image.transport() // => "https://loremflickr.com/640/480/transport"
faker.image.transport() // 'https://loremflickr.com/640/480/transport'
faker.image.transport(1234, 2345) // 'https://loremflickr.com/1234/2345/transport'
faker.image.transport(1234, 2345, true) // 'https://loremflickr.com/1234/2345/transport?lock=56789'

url

Generates a random image url.

Available since v8.0.0

Parameters

NameTypeDefaultDescription
options{ ... }{}

Options for generating a URL for an image.

options.height?number480

The height of the image.

options.width?number640

The width of the image.

Returns: string

ts
faker.image.url(options: {
  height: number,
  width: number
} = {}): string
faker.image.url() // => "https://picsum.photos/seed/IQBRxQqC/640/480"
faker.image.url() // 'https://loremflickr.com/640/480?lock=1234'

urlLoremFlickr

Generates a random image url provided via https://loremflickr.com.

Available since v8.0.0

Parameters

NameTypeDefaultDescription
options{ ... }{}

Options for generating a URL for an image.

options.category?string

Category to use for the image.

options.height?number480

The height of the image.

options.width?number640

The width of the image.

Returns: string

ts
faker.image.urlLoremFlickr(options: {
  category: string,
  height: number,
  width: number
} = {}): string
faker.image.urlLoremFlickr() // => "https://loremflickr.com/640/480?lock=494327256...
faker.image.urlLoremFlickr() // 'https://loremflickr.com/640/480?lock=1234'
faker.image.urlLoremFlickr({ width: 128 }) // 'https://loremflickr.com/128/480?lock=1234'
faker.image.urlLoremFlickr({ height: 128 }) // 'https://loremflickr.com/640/128?lock=1234'
faker.image.urlLoremFlickr({ category: 'nature' }) // 'https://loremflickr.com/640/480/nature?lock=1234'

urlPicsumPhotos

Generates a random image url provided via https://picsum.photos.

Available since v8.0.0

Parameters

NameTypeDefaultDescription
options{ ... }{}

Options for generating a URL for an image.

options.blur?1 | 10 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9false

Whether the image should be blurred.

options.grayscale?booleanfalse

Whether the image should be grayscale.

options.height?number480

The height of the image.

options.width?number640

The width of the image.

Returns: string

ts
faker.image.urlPicsumPhotos(options: {
  blur: 1 | 10 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9,
  grayscale: boolean,
  height: number,
  width: number
} = {}): string
faker.image.urlPicsumPhotos() // => "https://picsum.photos/seed/AIQBRxQq/640/480"
faker.image.urlPicsumPhotos() // 'https://picsum.photos/seed/NWbJM2B/640/480'
faker.image.urlPicsumPhotos({ width: 128 }) // 'https://picsum.photos/seed/NWbJM2B/128/480'
faker.image.urlPicsumPhotos({ height: 128 }) // 'https://picsum.photos/seed/NWbJM2B/640/128'
faker.image.urlPicsumPhotos({ grayscale: true }) // 'https://picsum.photos/seed/NWbJM2B/640/480?grayscale'
faker.image.urlPicsumPhotos({ blur: 4 }) // 'https://picsum.photos/seed/NWbJM2B/640/480?blur=4'
faker.image.urlPicsumPhotos({ blur: 4, grayscale: true }) // 'https://picsum.photos/seed/NWbJM2B/640/480?grayscale&blur=4'

urlPlaceholder

Generates a random image url provided via https://via.placeholder.com/.

Available since v8.0.0

Parameters

NameTypeDefaultDescription
options{ ... }{}

Options for generating a URL for an image.

options.backgroundColor?stringfaker.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?numberfaker.number.int({ min: 1, max: 3999 })

The height of the image.

options.text?stringfaker.lorem.words()

The text to display on the image.

options.textColor?stringfaker.color.rgb({ format: 'hex', prefix: '' })

The text color of the image.

options.width?numberfaker.number.int({ min: 1, max: 3999 })

The width of the image.

Returns: string

ts
faker.image.urlPlaceholder(options: {
  backgroundColor: string,
  format: 'gif' | 'jpeg' | 'jpg' | 'png' | 'webp',
  height: number,
  text: string,
  textColor: string,
  width: number
} = {}): string
faker.image.urlPlaceholder() // => "https://via.placeholder.com/2195x2371/fcdcbc/9...
faker.image.urlPlaceholder() // 'https://via.placeholder.com/150x180/FF0000/FFFFFF.webp?text=lorem'
faker.image.urlPlaceholder({ width: 128 }) // 'https://via.placeholder.com/128x180/FF0000/FFFFFF.webp?text=lorem'
faker.image.urlPlaceholder({ height: 128 }) // 'https://via.placeholder.com/150x128/FF0000/FFFFFF.webp?text=lorem'
faker.image.urlPlaceholder({ backgroundColor: '000000' }) // 'https://via.placeholder.com/150x180/000000/FFFFFF.webp?text=lorem'
faker.image.urlPlaceholder({ textColor: '000000' }) // 'https://via.placeholder.com/150x180/FF0000/000000.webp?text=lorem'
faker.image.urlPlaceholder({ format: 'png' }) // 'https://via.placeholder.com/150x180/FF0000/FFFFFF.png?text=lorem'
faker.image.urlPlaceholder({ text: 'lorem ipsum' }) // 'https://via.placeholder.com/150x180/FF0000/FFFFFF.webp?text=lorem+ipsum'
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+ipsum'

Released under the MIT License.