Image Aspect Ratio - lifelike/countersheetsextension GitHub Wiki

Inkscape’s default behavior is to stretch out any external image to fit the area it has been assigned. That is normally very useful. But when replacing images like the countersheetsextension does it can often be what is not expected. For instance if an external image is used to create a symbol on a counter and symbols of different sizes or shapes are substituted, with the default behavior the images have to be padded with different amounts of transparent pixels to avoid some of them being stretched (deformed).

There is no built-in way in the Inscape user interface or the countersheetsextension to avoid this, however there is a SVG attribute called preserveAspectRatio that is supported by Inkscape. It can be set like any other SVG attribute using the countersheetsextension. See the included example aspect_ratio.svg using one of the two example data files aspect_ratio.csv or aspect_ratio_h.csv. The two examples are to show the difference when the image is too wide or too narrow compared to the wanted shape on the counter.

This is what all the allowed values looks like when trying to use an image file that is too narrow for the template:

This is what it looks like with the same values when the image is instead too wide:

The value xMidYMid will preserve the image’s aspect ratio and insert it centered. That is probably the expected behavior that will work well for most situations. There is a complete list and rather technical description of all of this here: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/preserveAspectRatio

If some value (e.g. xMidYMid) is always wanted it can be easier to set it in the template rather than having to set it in the spreadsheet. Inkscape’s XML editor can be used for this. Normally every image inserted in Inkscape already has the preserveAspectRatio attribute, so you just have to find it and change it, and then it will be as expected when running the countersheetsextension as well.

See also: Set Image

⚠️ **GitHub.com Fallback** ⚠️