[ImageCDN] Add color image gen

This commit is contained in:
Ducko 2021-07-17 14:53:58 +01:00 committed by Alyxia Sother
parent c4026d1355
commit 98b463603a
No known key found for this signature in database
GPG Key ID: 355968D14144B739
1 changed files with 15 additions and 2 deletions

View File

@ -5,9 +5,9 @@ import { exec } from 'child_process';
import axios from 'axios';
export default (manifest) => {
return manifest.images ? Promise.all(manifest.images.map(async (x, i) => {
const baseDir = join(distDir, 'img', manifest.name);
const baseDir = join(distDir, 'img', manifest.name);
return manifest.images ? Promise.all(manifest.images.map(async (x, i) => {
const rawFile = join(baseDir, x.split('/').pop());
const rawExt = rawFile.split('.').pop();
@ -16,6 +16,19 @@ export default (manifest) => {
mkdirSync(baseDir, { recursive: true });
if (!x.includes('http')) {
console.log('color', x, i, finalFile);
try {
await new Promise((res) => exec(`convert -size 330x200 xc:${x.replace('(', '\\(').replace(')', '\\)')} "${finalFile}"`, res));
} catch (e) {
console.error('Failed to use ImageMagick to resize and compress, copying file as backup');
// copyFileSync(rawFile, finalFile);
}
return `/img/${manifest.name}/${finalName}`;
}
console.log(x, i, rawFile, finalFile);
const writer = createWriteStream(rawFile);