This commit is contained in:
2025-09-26 20:53:04 +02:00
parent d362f9e0ca
commit b56d7e69dd
5 changed files with 1051 additions and 1 deletions

View File

@ -0,0 +1,51 @@
import * as fs from 'fs';
import * as path from 'path';
import { convertImageVton } from '../lib/image-converter';
import * as dotenv from 'dotenv';
dotenv.config();
const clothesDir = 'C:\\Users\\ken\\Desktop\\VTON\\clothes';
const modelPath = 'C:\\Users\\ken\\Desktop\\VTON\\models\\Jessica_body.png';
const posesDir = 'C:\\Users\\ken\\Desktop\\VTON\\poses';
const outputDir = 'generated';
const comfyBaseUrl = process.env.SERVER1_COMFY_BASE_URL;
const comfyOutputDir = process.env.SERVER1_COMFY_OUTPUT_DIR;
async function generateVtonImages() {
if (!comfyBaseUrl || !comfyOutputDir) {
throw new Error("ComfyUI URL or Output Directory is not set in environment variables.");
}
const clothesFiles = fs.readdirSync(clothesDir).filter(file => /\.(jpg|png|jpeg)$/i.test(file));
const poseFiles = fs.readdirSync(posesDir).filter(file => /\.(jpg|png|jpeg)$/i.test(file));
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir);
}
for (let i = 0; i < clothesFiles.length; i++) {
const clothFile = clothesFiles[i];
const clothPath = path.join(clothesDir, clothFile);
const randomPoseFile = poseFiles[Math.floor(Math.random() * poseFiles.length)];
const posePath = path.join(posesDir, randomPoseFile);
console.log(`Processing cloth: ${clothFile} with pose: ${randomPoseFile}`);
const files = [modelPath, clothPath, posePath];
const prompt = "change clothes of image1 with image2";
const outputFilename = `model_${i}.png`;
const generatedImagePath = await convertImageVton(files, outputFilename, comfyBaseUrl, comfyOutputDir, { width: 720, height: 1280 });
if (generatedImagePath) {
console.log(`Generated image saved to ${generatedImagePath}`);
} else {
console.error(`Failed to generate image for ${clothFile}`);
}
}
}
generateVtonImages().catch(console.error);