mirror of
https://github.com/NovaGM/ModuleBuilder.git
synced 2024-08-15 00:23:33 +00:00
[ImageCDN] Add color image gen
This commit is contained in:
parent
c4026d1355
commit
98b463603a
1 changed files with 15 additions and 2 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue