PHP:使用inkscape将eps转换为svg

问题描述 投票:0回答:1

当我在终端中使用epssvg转换为inkscape时,它可以正常工作。但是,当我使用php的shell_exec执行相同的命令时,它不起作用。 (我也尝试过execsystem,但没有运气)

示例代码:

<?php

unlink('./sample.svg');
$file_path = realpath('./sample.eps');
$dest_path = getcwd() . '/sample.svg';

//# inkscape --file=sample.eps --export-plain-svg=sample.svg
// command works fine in terminal but not in php

$command = "inkscape --file=$file_path --export-plain-svg=$dest_path";
// command fails with no output (null)
$output = shell_exec($command);
var_dump($output);
var_dump(is_file('./sample.svg'));

同一命令也可以从php shell正常工作!我无法确定原因,因为我无法检查输出(它始终为null)

[ai -> svgpdf -> svg的转换效果很好

我怀疑这是与command works fine through terminal but not shell_exec php类似的问题,但是对这种情况的解决方案是什么?

PS:我正在使用this sample eps file进行测试

编辑:我在2>&1命令中添加了shell_exec,并获得了此输出

/srv/www/git/presta17_designer/eps/sample.eps:1: parser error : Start tag expected, '<' not found
%!PS-Adobe-3.0 EPSF-3.0
^
/srv/www/git/presta17_designer/eps/sample.eps:1: parser error : Start tag expected, '<' not found
%!PS-Adobe-3.0 EPSF-3.0
^

** (inkscape:717): WARNING **: 14:16:21.492: Specified document /srv/www/git/presta17_designer/eps/sample.eps cannot be opened (does not exist or not a valid SVG file)
php inkscape
1个回答
0
投票

我猜想权限。

PHP-shell可能有效,因为它在您的本地用户下运行。

检查您的Web服务器或PHP会话正在哪个用户下运行,并尝试与该用户一起在Terminal中运行Inkscape,以查看是否允许该操作。如果没有,请添加必要的权限。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.