( ′∀`)σ≡σ☆))Д′)レ(゚∀゚;)ヘ=З=З=Зε≡(ノ´_ゝ`)ノ
<?php
// Allowed output formats
$allowedFormats = ['png', 'jpeg', 'pdf'];
// Get POST parameters
$svgContent = $_POST['svg'] ?? '';
$id = $_POST['id'] ?? '130';
$svgContent = urldecode($svgContent);
$format = $_POST['format'] ?? 'png';
$format = strtolower($format);
if(empty($svgContent))
{
$svgContent = <<<SVG
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" style="background-color: #F5B069;">
<foreignObject x="0" y="0" width="200" height="200">
<div xmlns="http://www.w3.org/1999/xhtml" style="
width: 170px;
height: 122.4px;
margin: 0;
position: absolute;
top: 38.8px;
left: 15px;
display: flex;
align-items: center;
justify-content: center;
">
<svg style="background-color: #F5B069;" xmlns="http://www.w3.org/2000/svg" class="autocenter" viewBox="0 0 250 180" preserveAspectRatio="xMidYMid meet"><g transform="translate(0,50%)">
<defs xmlns:default="http://www.w3.org/2000/svg">
<style type="text/css">
@font-face {
font-family: 'Orbitron';
src: url('https://fonts.gstatic.com/s/orbitron/v19/yMJMMIlzdpvBhQQL_SC3X9yhF25-T1nyxSmxpmIyXjU1pg.ttf') format('woff');
}
.google-font-3 {
font-family: 'Orbitron', sans-serif;
font-size: 58px;
line-height:1.09;
fill: #4F0D28;
letter-spacing:0.02;
}
.google-font-slogan-3 {
font-family: 'Orbitron', sans-serif;
font-size: 38px;
line-height:-18.91;
fill: #4F0D28;
letter-spacing:0.02;
}
</style>
</defs><g xmlns:default="http://www.w3.org/2000/svg" transform="translate(10,20) scale(0.25)"><svg style="background-color: #F5B069;" xmlns="http://www.w3.org/2000/svg" fill="#4F0D28" viewBox="0 0 24 24" id="airplane" data-name="Flat Color" class="icon flat-color"><g transform="translate(24/2,24/2)"><path id="primary" d="M11.92,19.58,15.84,14H20a2,2,0,0,0,0-4H15.84L11.92,4.42A1,1,0,0,0,11.11,4h-.93a1,1,0,0,0-1,1.16L10,10H6.38L4.68,8.29A1.05,1.05,0,0,0,4,8H3a1,1,0,0,0-.89,1.45L3.38,12,2.11,14.55A1,1,0,0,0,3,16H4a1.05,1.05,0,0,0,.71-.29L6.38,14H10l-.81,4.84a1,1,0,0,0,1,1.16h.93A1,1,0,0,0,11.92,19.58Z" style="fill: rgb(0, 0, 0);"></path></g></svg></g><text fill="#6900AA" style="fill:#4F0D28;fill:#6900AA;" xmlns:default="http://www.w3.org/2000/svg" x="10" y="120" text-anchor="left" font-size="30" class="google-font-3">newx</text><text fill="#6900AA" style="fill:#4F0D28;fill:#6900AA;" xmlns:default="http://www.w3.org/2000/svg" x="10" y="154" text-anchor="left" font-size="7" class="google-font-slogan-3"></text></g></svg>
</div>
</foreignObject>
</svg>
SVG;
}
if (empty($svgContent)) {
http_response_code(400);
echo "Error: Missing SVG content.";
exit;
}
if (!in_array($format, $allowedFormats)) {
http_response_code(400);
echo "Error: Invalid output format. Allowed formats: " . implode(', ', $allowedFormats);
exit;
}
// Ensure tmp directory exists
$tmpDir = __DIR__ . '/uploads/logos/';
if (!is_dir($tmpDir)) {
mkdir($tmpDir, 0777, true);
}
// Save base64-encoded SVG to temp file
$tmpSvgFile = $tmpDir . 'svg_' . uniqid() . '.txt';
file_put_contents($tmpSvgFile, base64_encode($svgContent));
// Define output file path with correct extension
$tmpOutputFile = $tmpDir . $id . '.' . $format;
// Node.js script path
$nodeScript = __DIR__ . '/savePNG.js';
// Build command to run Node.js script
// Pass SVG file path, output file path, and output format
$cmd = escapeshellcmd("node '$nodeScript' '$tmpSvgFile' '$tmpOutputFile' '$format'") . ' 2>&1';
// Execute command
exec($cmd, $output, $returnVar);
if ($returnVar !== 0 || !file_exists($tmpOutputFile)) {
http_response_code(500);
echo "Error: Conversion failed.<br>";
echo "Details:<br>" . implode("<br>", $output);
@unlink($tmpSvgFile);
exit;
}
// Mime types for output formats
$mimeTypes = [
'png' => 'image/png',
'jpeg' => 'image/jpeg',
'pdf' => 'application/pdf',
];
$mime = $mimeTypes[$format] ?? 'application/octet-stream';
// Send headers for file download
header('Content-Description: File Transfer');
header('Content-Type: image/png');
header('Content-Disposition: attachment; filename="converted.' . $format . '"');
header('Content-Length: ' . filesize($tmpOutputFile));
header('Cache-Control: no-cache, no-store, must-revalidate');
header('Pragma: no-cache');
header('Expires: 0');
// Output the file
readfile($tmpOutputFile);
// Clean up temp files
@unlink($tmpSvgFile);
//@unlink($tmpOutputFile);
exit;