Inkscape.org
Beyond the Basics PHP: use inkscape to convert eps to svg
  1. #1
    unlocomqx unlocomqx @unlocomqx
    *

    Hello,

    When I convert eps to svg in the terminal using inkscape, it works fine.
    But when I execute the same command using php's shell_exec, it doesn't work. (I also tried exec and system with no luck)

    Sample code:

    <?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'));

     

    The same command also works correctly from php shell!
    I couldn't determine the cause because I couldn't check the output (it's always null)

    Conversion worked fine with ai -> svg and pdf -> svg

    I suspect that this is a similar issue to command works fine through terminal but not shell_exec php but what would be the solution to this case?

    PS: I'm using this sample eps file for testing

    Any help is much appreciated, Thank you

  2. #2
    unlocomqx unlocomqx @unlocomqx

    Here's the output I got from php

    Failed to get connection ** (inkscape:681): CRITICAL **: 14:12:37.193: dbus_g_proxy_new_for_name: assertion 'connection != NULL' failed ** (inkscape:681): CRITICAL **: 14:12:37.193: dbus_g_proxy_call: assertion 'DBUS_IS_G_PROXY (proxy)' failed ** (inkscape:681): CRITICAL **: 14:12:37.193: dbus_g_connection_register_g_object: assertion 'connection != NULL' failed /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:681): WARNING **: 14:12:37.320: Specified document /srv/www/git/presta17_designer/eps/sample.eps cannot be opened (does not exist or not a valid SVG file)
  3. #3
    unlocomqx unlocomqx @unlocomqx

    I found the solution

    http://www.inkscapeforum.com/viewtopic.php?t=19303 

  4. #4
    brynn brynn @brynn

    Welcome to the forum!

    I have not replied to your message, because it's over my head.  But I wanted to say thanks for your research and thanks for sharing the solultion you found.  I'm sure others will find it helpful.

  5. #5
    unlocomqx unlocomqx @unlocomqx

    Thank you,

    In fact, a simpler solution would be to add PATH=/usr/bin to the command like so

    $command = "PATH=/usr/bin inkscape --file=$file_path --export-plain-svg=$dest_path";

    Cheers

  6. #6
    Mihaela Jurković Mihaela Jurković @prkos⛰️🌌

    Good to know! I haven't played with Inkscape CLI in a long while but it can be super useful :)

Inkscape Inkscape.org Inkscape Forum Beyond the Basics PHP: use inkscape to convert eps to svg