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.

76 lines
3.1 KiB

4 years ago
<?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_name = $_POST['dir_name'];
$without_extension = pathinfo($file_name, PATHINFO_FILENAME);
echo "Desired directory name is: ".$dir_name."</br>";
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) {
//$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. The actual workhorse is <a href="https://inkscape.org/">inkscape</a>. 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>