Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(generator): implement fix(?) for issue #4 #5

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 26 additions & 6 deletions src/util/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ export const generator = async (
const key = options.key || options.k;
const id = options.id ? options.id : customId();

const customCount = options.count || options.c;
const customColors = options.colors || options.cs;

if (width > MAX_DIMENSION || height > MAX_DIMENSION) {
throw new Error(`Dimensions must be no greater than ${MAX_DIMENSION}`);
}
Expand Down Expand Up @@ -171,18 +174,35 @@ export const generator = async (
}
}

const [svg, canvas] = patterns[options.type || options.t || `simple`]({
...allOptions,
colors:
(options.colors || options.cs)?.split(`-`)?.map(fixHexColorString) ||
randomColor({
count,
let colors: string[] =
(options.colors || options.cs)?.split(`-`)?.map(fixHexColorString) ||
randomColor({
count,
hue,
luminosity,
seed,
format,
alpha,
});

if (customColors && customCount && count > colors.length) {
const countDiff = count - colors.length;
colors = [
...colors,
...randomColor({
count: countDiff,
hue,
luminosity,
seed,
format,
alpha,
}),
];
}

const [svg, canvas] = patterns[options.type || options.t || `simple`]({
...allOptions,
colors,
});

await redis.incr(`numberOfImagesCreated`);
Expand Down