@pictwo/faker
v1.1.0
Published
Faker.js image module backed by the Pictwo placeholder image API.
Maintainers
Readme
@pictwo/faker
A Faker.js image module backed by Pictwo. Drop it onto
faker to make every generated image URL resolve to the hosted ArkStack image API
(or any provider supported by @pictwo/core).
pnpm add @pictwo/faker @faker-js/fakerUsage
import { faker } from '@faker-js/faker';
import { pictwoImage } from '@pictwo/faker';
export const fake = {
...faker,
image: pictwoImage(),
};
fake.image.url(); // https://pictwo.toneflix.net/640/480
fake.image.avatar(); // https://pictwo.toneflix.net/category/avatar/128/128
fake.image.fashion(); // https://pictwo.toneflix.net/category/fashion/640/480The default provider is the hosted API at https://pictwo.toneflix.net.
pictwoImage is an alias of createFakerImage.
Methods
| Method | Route |
| ------------------- | ----------------------------------------- |
| url() | /{width}/{height} |
| avatar() | /category/avatar/{width}/{height} |
| fashion() | /category/fashion/{width}/{height} |
| fabric() | /category/fabric/{width}/{height} |
| product() | /category/product/{width}/{height} |
| design() | /category/design/{width}/{height} |
| urlPicsumPhotos() | /{width}/{height} |
| urlLoremFlickr() | /images/{category}?w={width}&h={height} |
urlPicsumPhotos() also understands Faker's grayscale and blur options:
fake.image.urlPicsumPhotos({
width: 100,
height: 100,
grayscale: true,
blur: 4,
});
// https://pictwo.toneflix.net/100/100?filters=greyscale,blur:4Any Faker image method that Pictwo does not implement (e.g. dataUri) throws a clear
Not implemented error.
Configuration
createFakerImage(config?) accepts the full @pictwo/core
PictwoConfig, plus default width/height:
pictwoImage({
width: 1000,
height: 800,
source: { driver: 'hosted', baseUrl: 'https://img.example.com' },
});