use sharp and improve prompting
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import sharp from 'sharp';
|
||||
import path from "path";
|
||||
import { mkdir, writeFile } from "fs/promises";
|
||||
import { fileURLToPath } from "url";
|
||||
@@ -7,7 +8,27 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const COMFYUI_URL = process.env.COMFYUI_URL || "http://localhost:8188";
|
||||
|
||||
// Drawing style prefix
|
||||
const STYLE_PREFIX = `clean line art, minimalist sketch, concept art sketch, black and white line drawing, lots of white space, sparse shading, simple black hatching, very low detail, subtle color accent`;
|
||||
const STYLE_PREFIX = `clean line art, minimalist sketch, concept art sketch, black and white line drawing, lots of white space, sparse shading, very minimal shading, simple black hatching, very low detail, single accent color`;
|
||||
|
||||
async function upscaleImage(inputPath, outputPath, width, height) {
|
||||
try {
|
||||
await sharp(inputPath)
|
||||
.resize(width, height, { kernel: 'lanczos3' })
|
||||
.blur(0.3)
|
||||
.sharpen()
|
||||
.png({
|
||||
compressionLevel: 9,
|
||||
adaptiveFiltering: true,
|
||||
palette: true
|
||||
})
|
||||
.toFile(outputPath);
|
||||
console.log(`Upscaled + compressed PNG saved: ${outputPath}`);
|
||||
return outputPath;
|
||||
} catch (err) {
|
||||
console.error("Error during upscaling:", err.message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// 1. Generate engineered visual prompt
|
||||
async function generateVisualPrompt(flavor) {
|
||||
@@ -156,7 +177,7 @@ async function downloadImage(filename, localFilename) {
|
||||
|
||||
// 4c. Submit prompt and handle full image pipeline
|
||||
async function generateImageViaComfyUI(prompt, filename) {
|
||||
const negativePrompt = `heavy shading, deep blacks, cross-hatching, dark, gritty, shadow-filled, chiaroscuro, scratchy lines, photorealism, hyper-realistic, high detail, 3D render, CGI, polished, smooth shading, detailed textures, noisy, cluttered, blurry, text, logo, signature, watermark`;
|
||||
const negativePrompt = `heavy shading, deep blacks, cross-hatching, dark, gritty, shadow-filled, chiaroscuro, scratchy lines, photorealism, hyper-realistic, high detail, 3D render, CGI, polished, smooth shading, detailed textures, noisy, cluttered, blurry, text, logo, signature, watermark, artist name, branding, ugly, deformed, unnatural patterns, perfect curves, repetitive textures`;
|
||||
const workflow = buildComfyWorkflow(prompt, negativePrompt);
|
||||
|
||||
try {
|
||||
@@ -196,12 +217,19 @@ export async function generateDungeonImages({ flavor }) {
|
||||
const finalPrompt = await generateVisualPrompt(flavor);
|
||||
console.log("Engineered visual prompt:\n", finalPrompt);
|
||||
|
||||
const filename = `dungeon.png`;
|
||||
const filepath = await generateImageViaComfyUI(finalPrompt, filename);
|
||||
const baseFilename = `dungeon.png`;
|
||||
const upscaledFilename = `dungeon_upscaled.png`;
|
||||
|
||||
const filepath = await generateImageViaComfyUI(finalPrompt, baseFilename);
|
||||
if (!filepath) {
|
||||
throw new Error("Failed to generate dungeon image.");
|
||||
}
|
||||
|
||||
return filepath;
|
||||
// Upscale 2x (half of A4 at 300dpi)
|
||||
const upscaledPath = await upscaleImage(filepath, upscaledFilename, 1456, 1024);
|
||||
if (!upscaledPath) {
|
||||
throw new Error("Failed to upscale dungeon image.");
|
||||
}
|
||||
|
||||
return upscaledPath;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user