I need to convert ai and eps files to svg to use with a product customization tool. To do this, I convert from ai or eps to eps (to remove any artboard or white spaces around the file) and then to svg. All this is done after upload of original file with this PHP code :
if(!empty($_FILES))
{
//$rustart = getrusage();
//var_dump($_FILES);
$tempFile = $_FILES['file']['tmp_name'];
$filePrefix = "file_" . time() . "_";
$targetName = $this->santitizeFilename($_FILES['file']['name']);
//var_dump($targetName);
$finalName = $filePrefix . $targetName;
$targetFile = $rootFolder . $ds . $finalName;
move_uploaded_file($tempFile, $targetFile);
$response['filepath'] = $relativeFolder . $ds . $this->getFilenameWithExtension($targetFile);
//$response['success'] = file_exists($targetFile);
$response['id_file'] = -1;
$ext = pathinfo($targetFile, PATHINFO_EXTENSION);
if($ext == 'svg')
{
$response['filepath'] = $relativeFolder . $ds . $this->replaceExtension($targetFile, 'svg');
}
if($ext == 'ai' || $ext == 'eps')
{
$epsPath = $rootFolder . $ds . $this->replaceExtension($targetFile, 'eps');
$epsCmd = "inkscape " . $targetFile . " -D -E " . $epsPath;
$startEps = microtime(true);
exec($epsCmd);
$endEps = microtime(true);
$svgPath = $rootFolder . $ds . $this->replaceExtension($targetFile, 'svg');
$svgCmd = "inkscape " . $epsPath . " --export-plain-svg=" . $svgPath;
$startSvg = microtime(true);
exec($svgCmd);
$endSvg = microtime(true);
$response['epsTime'] = $endEps - $startEps;
$response['svgTime'] = $endSvg - $startSvg;
$response['filepath'] = $relativeFolder . $ds . $this->replaceExtension($targetFile, 'svg');
$vectorFile = new MCVectorFile();
$vectorFile->url = $epsPath;
if($vectorFile->save()){
$response['id_file'] = $vectorFile->id;
}
}
When logging the times $epsTime and $svgTime I get about 12 seconds everytime. This is really long and I don't see it scaling well with multiple users on the site uploading files at the same time...
Also running only one command does not improve the time, it still takes about 12 seconds per command.
Is there any way I can speed this up ? Is there any other way I can make this conversion other than inkscape ?
EDIT : So I have tried running a shell script instead and it takes the same time, however, if I run the script directly on the server it takes way less time. So it seems the problem is some waiting because of missing permissions even though the files are finally created. This is the output I get when running from php :
** (inkscape:31337): WARNING **: Unable to create profile directory (Permission denied) (13)
** Message: Cannot create profile directory /usr/share/httpd/.config/inkscape.
** Message: Inkscape will run with default settings, and new settings will not be saved.
** (inkscape:31337): WARNING **: Could not create extension error log file '/usr/share/httpd/.config/inkscape/extension-errors.log'
** (inkscape:31344): WARNING **: Unable to create profile directory (Permission denied) (13)
** Message: Cannot create profile directory /usr/share/httpd/.config/inkscape.
** Message: Inkscape will run with default settings, and new settings will not be saved.
** (inkscape:31344): WARNING **: Could not create extension error log file '/usr/share/httpd/.config/inkscape/extension-errors.log'
I'm not sure I should give permissions to those folders to apache. But it seems those are configurations of inkscape that I probably don't need for what I'm doing. So is there any way I can bypass this ?
EDIT 2: So after giving the permissions on the folder I have no output from the script anymore, files are created but it still takes an insane amount of time compared to running directly on the server.