mirror of
https://github.com/immich-app/immich.git
synced 2025-03-01 15:11:21 +01:00
32 lines
658 B
TypeScript
32 lines
658 B
TypeScript
![]() |
import { PNG } from 'pngjs';
|
||
|
|
||
|
const createPNG = (r: number, g: number, b: number) => {
|
||
|
const image = new PNG({ width: 1, height: 1 });
|
||
|
image.data[0] = r;
|
||
|
image.data[1] = g;
|
||
|
image.data[2] = b;
|
||
|
image.data[3] = 255;
|
||
|
return PNG.sync.write(image);
|
||
|
};
|
||
|
|
||
|
function* newPngFactory() {
|
||
|
for (let r = 0; r < 255; r++) {
|
||
|
for (let g = 0; g < 255; g++) {
|
||
|
for (let b = 0; b < 255; b++) {
|
||
|
yield createPNG(r, g, b);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
const pngFactory = newPngFactory();
|
||
|
|
||
|
export const makeRandomImage = () => {
|
||
|
const { value } = pngFactory.next();
|
||
|
if (!value) {
|
||
|
throw new Error('Ran out of random asset data');
|
||
|
}
|
||
|
|
||
|
return value;
|
||
|
};
|