return ob_get_clean();
});
add_action(‘wp_ajax_tp_giatheu_vs1’, ‘tp_giatheu_vs1_handle’);
add_action(‘wp_ajax_nopriv_tp_giatheu_vs1’, ‘tp_giatheu_vs1_handle’);
function tp_giatheu_vs1_handle(){
try{
if(!check_ajax_referer(‘tp_gt_vs1_nonce’,’nonce’,false)) throw new Exception(‘Nonce không hợp lệ.’);
if(empty($_FILES[‘image’])) throw new Exception(‘Chưa nhận được file ảnh.’);
$f = $_FILES[‘image’];
if($f[‘error’] !== UPLOAD_ERR_OK) throw new Exception(‘Upload lỗi: ‘.$f[‘error’]);
$mime = mime_content_type($f[‘tmp_name’]);
if(!in_array($mime, [‘image/png’,’image/jpeg’])) throw new Exception(‘Chỉ nhận PNG/JPG.’);
// Đọc file ảnh vào memory
$imagePath = $f[‘tmp_name’];
// Prompt “giả thêu satin” (VS1)
$prompt = “Use the uploaded image as content. Keep original colors & layout. ”
. “STYLE = SATIN EMBROIDERY (Vietnamese ‘giả thêu’ look). ”
. “Re-draw using contour-parallel satin hatching per region (no solid fills). ”
. “Short satin strokes with tapered ends, slight saw-tooth edges. ”
. “Thread width tiers: 0.28–0.40 mm (highlight), 0.40–0.55 mm (midtone), 0.55–0.75 mm (shadow). ”
. “Row spacing: 1.0–1.6 mm varying by tone; keep flowing curvature per region. ”
. “Output clean PNG with transparent background.”;
// Gọi OpenAI Images API (edits) với model gpt-image-1
$ch = curl_init(‘https://api.openai.com/v1/images/edits’);
$headers = [
‘Authorization: Bearer ‘ . OPENAI_API_KEY
];
