generate.ts · TypeScript
import { BestPNG } from '@bestpng/sdk';
const bp = new BestPNG({ apiKey: process.env.BP_API_KEY });
// 1. Upload a flat-lay product image
const upload = await bp.images.upload('./shirt.png');
// 2. Generate model try-on shots
const job = await bp.workspace.tryOn({
productImage: upload.id,
model: { gender: 'female', region: 'asian' },
scene: 'studio',
count: 4,
resolution: '2048',
});
// 3. Subscribe to results
job.on('image', (img) => download(img.url));
job.on('done', () => console.log('All', job.count, 'ready'));