Inkscape inside PHP/Apache doesn't render fonts to PNG

余生长醉 提交于 2019-11-26 08:35:34

问题


An issue I discover today is similar to this unanswered problem; though not the same, it may have the same cause.

I\'m rendering SVG files using inkscape, as either PNG or PDF. For the most part I intend to use Gearman to render these in the background, but for now I am creating some thumbnails inside a PHP/Apache process. It seems that if inkscape is called (via PHP\'s exec) inside an Apache process, it cannot find the fonts it needs to render. Thus, the graphic elements render fine, but any text elements are not drawn in the PNG output.

I suspect that the CLI environment from inside Apache is different to my usual bash console in a way that means fonts cannot be seen. I\'m on OS X 10.6.8. Any ideas?

Edit: following on from comments, I\'ve captured php -i inside both Apache and Gearman, and diffed the first against the second (so in theory applying the diff would make it work). The result is here.

Edit 2: I\'ve tried convert -list font in both environments using system - no differences at all.


回答1:


As was determined in the comments above, this was caused by an environmental difference - the HOME env var was set differently inside the executed process. Using proc_open instead of simple exec gave more precise control over said process and explicitly setting that env var solved the issue.




回答2:


For the record, here's the usage of proc_open that helped fix this issue:

$command = "{$exec} --without-gui {$params} {$file} {$redirect}";
$return = -1;
// Comment this out for now
//exec($command, self::$output, $return);

$descriptorspec = array(
    0 => array("pipe", "r"),
    1 => array("pipe", "w"),
    2 => array("file", "/dev/null", "a")
);
$pipes = array();
$env = array(
    // Try additional stuff here, but culprit was:
    'HOME' => '/Users/jon',
);
$resource = proc_open(
    $command,
    $descriptorspec,
    $pipes,
    $cwd = null,
    $env
);


来源:https://stackoverflow.com/questions/9967217/inkscape-inside-php-apache-doesnt-render-fonts-to-png

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!