interface-forge - v2.5.0
    Preparing search index...

    Class ImageModule

    Module to generate images.

    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(), or personPortrait() which has more control over the size and sex of the person.

    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.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    faker: Faker

    Methods

    • Generates a random avatar image url.

      Returns string

      faker.image.avatar()
      // 'https://avatars.githubusercontent.com/u/97165289'

      2.0.1

    • Generates a random avatar from GitHub.

      Returns string

      faker.image.avatarGitHub()
      // 'https://avatars.githubusercontent.com/u/97165289'

      8.0.0

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

      Returns string

      faker.image.avatarLegacy()
      // 'https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/170.jpg'

      8.0.0

      The links are no longer working. Use avatar() instead.

    • Generates a random data uri containing an URL-encoded SVG image or a Base64-encoded SVG image.

      Parameters

      • Optionaloptions: {
            color?: string;
            height?: number;
            type?: "svg-uri" | "svg-base64";
            width?: number;
        }

        Options for generating a data uri.

        • Optionalcolor?: string

          The color of the image. Must be a color supported by svg.

          faker.color.rgb()
          
        • Optionalheight?: number

          The height of the image.

          faker.number.int({ min: 1, max: 3999 })
          
        • Optionaltype?: "svg-uri" | "svg-base64"

          The type of the image to return. Consisting of the file extension and the used encoding.

          faker.helpers.arrayElement(['svg-uri', 'svg-base64'])
          
        • Optionalwidth?: number

          The width of the image.

          faker.number.int({ min: 1, max: 3999 })
          

      Returns string

      faker.image.dataUri() // 'data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http...'
      faker.image.dataUri({ type: 'svg-base64' }) // 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3...'

      4.0.0

    • Generates a random square portrait (avatar) of a person. These are static images of fictional people created by an AI, Stable Diffusion 3. The image URLs are served via the JSDelivr CDN and subject to their terms of use.

      Parameters

      • Optionaloptions: { sex?: "female" | "male"; size?: 32 | 128 | 512 | 256 | 64 }

        Options for generating an AI avatar.

        • Optionalsex?: "female" | "male"

          The sex of the person for the avatar. Can be 'female' or 'male'.

          faker.person.sexType()
          
        • Optionalsize?: 32 | 128 | 512 | 256 | 64

          The size of the image. Can be 512, 256, 128, 64 or 32.

          512
          

      Returns string

      faker.image.personPortrait() // 'https://cdn.jsdelivr.net/gh/faker-js/assets-person-portrait/female/512/57.jpg'
      faker.image.personPortrait({ sex: 'male', size: '128' }) // 'https://cdn.jsdelivr.net/gh/faker-js/assets-person-portrait/male/128/27.jpg'

      9.5.0

    • Generates a random image url.

      Parameters

      • Optionaloptions: { height?: number; width?: number }

        Options for generating a URL for an image.

        • Optionalheight?: number

          The height of the image.

          faker.number.int({ min: 1, max: 3999 })
          
        • Optionalwidth?: number

          The width of the image.

          faker.number.int({ min: 1, max: 3999 })
          

      Returns string

      faker.image.url() // 'https://loremflickr.com/640/480?lock=1234'
      

      8.0.0

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

      Parameters

      • Optionaloptions: { category?: string; height?: number; width?: number }

        Options for generating a URL for an image.

        • Optionalcategory?: string

          Category to use for the image.

        • Optionalheight?: number

          The height of the image.

          faker.number.int({ min: 1, max: 3999 })
          
        • Optionalwidth?: number

          The width of the image.

          faker.number.int({ min: 1, max: 3999 })
          

      Returns string

      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'

      8.0.0

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

      Parameters

      • Optionaloptions: {
            blur?: 0 | 1 | 2 | 5 | 3 | 10 | 8 | 4 | 6 | 7 | 9;
            grayscale?: boolean;
            height?: number;
            width?: number;
        }

        Options for generating a URL for an image.

        • Optionalblur?: 0 | 1 | 2 | 5 | 3 | 10 | 8 | 4 | 6 | 7 | 9

          Whether the image should be blurred. 0 disables the blur.

          faker.number.int({ max: 10 })
          
        • Optionalgrayscale?: boolean

          Whether the image should be grayscale.

          faker.datatype.boolean()
          
        • Optionalheight?: number

          The height of the image.

          faker.number.int({ min: 1, max: 3999 })
          
        • Optionalwidth?: number

          The width of the image.

          faker.number.int({ min: 1, max: 3999 })
          

      Returns string

      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'

      8.0.0

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

      Parameters

      • Optionaloptions: {
            backgroundColor?: string;
            format?: "gif" | "jpeg" | "jpg" | "png" | "webp";
            height?: number;
            text?: string;
            textColor?: string;
            width?: number;
        }

        Options for generating a URL for an image.

        • OptionalbackgroundColor?: string

          The background color of the image.

          faker.color.rgb({ format: 'hex', prefix: '' })
          
        • Optionalformat?: "gif" | "jpeg" | "jpg" | "png" | "webp"

          The format of the image.

          faker.helpers.arrayElement(['gif', 'jpeg', 'jpg', 'png', 'webp'])
          
        • Optionalheight?: number

          The height of the image.

          faker.number.int({ min: 1, max: 3500 })
          
        • Optionaltext?: string

          The text to display on the image.

          faker.lorem.words()
          
        • OptionaltextColor?: string

          The text color of the image.

          faker.color.rgb({ format: 'hex', prefix: '' })
          
        • Optionalwidth?: number

          The width of the image.

          faker.number.int({ min: 1, max: 3500 })
          

      Returns string

      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'

      8.0.0

      The service has bad uptime. Use faker.image.url() or faker.image.dataUri() instead.