Inkscape.org
Beyond the Basics Command line help
  1. #1
    xpat xpat @xpat

    OK here is my issue- I would like to use the command line to insert a .bmp image at a specific location and size. I have searched in the appropriate places but I have not figured out the command that I need. Could someone point me in the right direction? Much Thanks!!

    For additional information I am trying to do this on Lubuntu with Inkscape version 1.2.2 though I do have Inkscape installed on a couple of Windows boxes.

    I can/have done this manually with the gui interface but it takes me about 2 hours. I was trying to automate the process with C++ as I have done in the past. With about 1100 files to create, I am not looking forward to spending the next year dragging and dropping

  2. #2
    inklinea inklinea @inklinea⛰️
    *

    As a side note, svg is only required to support png and jpeg. 

    If you make a non compliant svg with bmp, webp you are at the mercy of the target system.

    Browsers are generally quite forgiving, some other software not.

    -----------------------------------------------------------------
    There are two main types of images in SVGs, embedded and linked.

    Embedded are base64 data strings, where are just xlink:href (or href) in the <image> tag.

    -----------------------------------------------------------------

    When you say 'command line' it depends what you mean.

    - Purely the inkscape command line 

    Cannot create elements, but change attributes and style properties of existing object.

    So if you have a template svg you could use `object-set-attribute`

    1. Set the xlink:href attribute for an existing <image> tag.
    2. Set the x, y, width, height attributes.
    3. Use `export-filename` and `export-do` to save a new svg or png etc.

    ------------------------------------------------------------------

    The above method is not very good on its own however because it does not provide a way to adjust for images of different sizes and aspect ratios.
    On Ubuntu it is possible to use other tools before using the Inkscape command line. 

    There is a bash script example on this forum written by me, which uses the ImageMagick `indentify` command to get pixel height / width from a bitmap then build and run an Inkscape command line. I just can't find it on the forum at the moment.

    -------------------------------------------------------------------

    If you don't need headless operation and you can write a bit of python, then the easiest way to do it is using an Inkscape extension to batch process your images.

    Inkscape is bundled with the Python imaging library - PIL (pillow) on Windows and PIL is included ( or easily installed ) with most Linux distros.
    PIL can open a large range of different bitmap formats and the PIL Image() object is easy to read, manipulate.

    I've attached a zip file with an example extension for importing an image.

    This imports an image to the canvas. However to save an svg from an extension it's as simple as svg.tostring().decode('utf-8) then save the string.
    Alternatively you could use a command call to save or batch process the svgs through the Inkscape command line if you need to correct the text formatting.

    ------------------------------------------------------------------

    Another option is to make a python venv, install inkex ( the Inkscape extension system ) from pypi along with PIL.
    This doesn't even need Inkscape and can run headless on a server.

  3. #3
    xpat xpat @xpat

    Thank you for the detailed response but I think I figured it out. I went back through my old C++ code, and evidently I have figured this out before. Chalk it up to getting old. I found that I can specify a .bmp file directly and export it as .svg with this command [inkscape --export-filename=(output filename and svg extension) (input filename and .bmp extension)] From there I can read in what I need to a temp file and convert it to pdf. It takes an extra step but I can control the location and size as you described in step 2. This method creates a file for me in less than 10 seconds instead of 2 hours. Thanks again for your response.