Skip to content

Instantly share code, notes, and snippets.

@ogaty
Last active May 24, 2023 01:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ogaty/3b1747fe678fee95f43502f03e63d8e3 to your computer and use it in GitHub Desktop.
Save ogaty/3b1747fe678fee95f43502f03e63d8e3 to your computer and use it in GitHub Desktop.
svg
<html>
<head>
</head>
<body>
<form method="POST" enctype="multipart/form-data">
<input type="file" name="svg" id="svg">
<input type="submit">
</form>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$svgFile = $_FILES['svg'];
$svg = simplexml_load_file($svgFile['tmp_name']);
echo '<div style="height: 400px;">';
echo $svg->asXML();
echo '</div>';
$svg->g->text = '';
$newText = $svg->g->addChild('text', 'ううううう');
//$newText->addAttribute('x', '414.412px');
//$newText->addAttribute('y', '369.555px');
foreach ($svg->g->text[0]->attributes() as $key => $val) {
$newText->addAttribute($key, $val);
}
echo '<div style="height: 400px;">';
echo $svg->asXML();
echo '</div>';
file_put_contents('いいいいい.svg', $svg->asXML());
echo 'success';
}
?>
<script>
document.getElementById('svg').addEventListener('change', function(event) {
document.querySelector('#img').src = event.target.files[0];
const file = event.target.files[0]
const reader = new FileReader()
reader.onload = (event) => {
// document.querySelector('#img').src = event.target.result;
}
reader.readAsDataURL(file);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment