edemaine / svgtiler

Tool for drawing diagrams on a grid, combining grids of SVGs into a big SVG figure
MIT License
61 stars 6 forks source link

<image> inlining #42

Closed edemaine closed 4 years ago

edemaine commented 5 years ago

I think there should be a command-line option to inline all <image>s (including but not limited to those specified by just an image filename), as the resulting SVG is probably what people usually want (unless immediately converting to PDF or PNG, where they are inlined anyway, so why bother being small in the intermediate file?). Indeed, I think this option should be the default, and there's a command-line option to not inline images.

This was originally discussed in #10, and came up again in puuull.coffee where @diomidov wrote the following code to inline images in a CoffeeScript mapping file:

image = (file) ->
    bitmap = fs.readFileSync(file)
    base64 = new Buffer(bitmap).toString('base64')
    preact.h('image', {
        'xlink:href': "data:image/png;base64,#{base64}"
    })

We might want to deduplicate <image>s that refer to a common filename (but may be included in multiple symbols) via another level of <symbol>s. We could even consider doing this deduplication for inlined SVG (included via filenames), e.g. if blank and space both get mapped to blank.svg -- less clear this is worth it, though. (This aspect is replaced by #50.)

In our automatic bbox code, it'd also be nice to handle <image>s, ideally also with transform:scale(...) set, so that we can easily include images at different sizes (and with this change, have them inlined).