Dockerized web application to conveniently convert SVG to LaTeX files.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

90 lines
3.8 KiB

<?php
/*
The ugliest webapp in the world to convert SVG to LaTeX using inkscape.
Copyright (C) 2020 Maximilian Stiefel (stiefel.maximilian@online.de)
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; version 2.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
*/
if(isset($_FILES['image']) && $_FILES['image']['error'] === UPLOAD_ERR_OK) {
$errors= array();
$file_name = $_FILES['image']['name'];
$file_size =$_FILES['image']['size'];
$file_tmp =$_FILES['image']['tmp_name'];
$file_type=$_FILES['image']['type'];
$file_ext=strtolower(end(explode('.',$_FILES['image']['name'])));
$extensions= array("svg");
$upload_dir = "./images/";
$dir_str = $without_extension = pathinfo($file_name, PATHINFO_FILENAME);
$dir_name = "";
if (preg_match("/^[a-zA-Z0-9_]*$/", $_POST['dir_name'])) {
$dir_name = $_POST['dir_name'];
} else {
$errors[] = "Error: For a directory name only alphanumeric characters and underscore are allowed.";
}
if (strlen($dir_name) == 0) {
$errors[] = "Error: Please enter directory name.";
}
if(in_array($file_ext,$extensions)=== false) {
$errors[]="Error: Extension not allowed, please choose a JPEG or PNG file.";
}
if(empty($errors)==true) {
echo "Desired directory name is: ".$dir_name."</br>";
//$new_name = md5(time() . $file_name);
unlink($upload_dir.$file_name);
unlink($upload_dir.$without_extension.".pdf");
unlink($upload_dir.$without_extension.".pdf_tex");
if (move_uploaded_file($file_tmp, $upload_dir.$file_name)) {
echo "Upload successful.</br>";
//$current_dir = getcwd();
//echo "Current directory is ".$current_dir."</br>";
$output = shell_exec("./svg-to-latex.sh ".$upload_dir.$file_name." ".$dir_name);
echo "</p>";
echo "Conversion results : </br>";
?>
<a href="<?php echo $upload_dir.$without_extension.".pdf";?>" target="_blank"><?php echo $upload_dir.$without_extension.".pdf";?></a> </br>
<a href="<?php echo $upload_dir.$without_extension.".pdf_tex";?>" target="_blank"><?php echo $upload_dir.$without_extension.".pdf_tex";?></a></p>
<?php
echo "Console output: </br>";
echo "<pre>$output</pre>";
} else {
echo "Error: File could not be moved to target directory.</br>";
}
} else {
print_r($errors);
}
}
?>
<html>
<body>
This little tool allows to convert vector graphics to latex. </br>
The actual workhorse is <a href="https://inkscape.org/">inkscape</a>.
<p>vector2latex, Copyright (C) 2020 Maximilian Stiefel </br> vector2latex
comes with ABSOLUTELY NO WARRANTY; for details click <a
href=https://git.stiefel.tech/m3x1m0m/vector2latex/src/branch/master/LICENSE>here</a>.
This is free software, and you are welcome to redistribute it under certain
conditions; for details click <a
href=https://git.stiefel.tech/m3x1m0m/vector2latex/src/branch/master/LICENSE>here</a>.
</p>
Please upload the .svg file you wish to convert.
<form action="" method="POST" enctype="multipart/form-data">
Directory where you store images e.g. fig: <input type="text" name="dir_name"></br>
<input type="file" name="image" /></br>
<input type="submit" value="Convert"/>
</form>
</body>
</html>