I'm trying to place an arbitrary image as a background of an SVG which has a fixed size. The desired behavior is for an image which is larger than the fixed size of the SVG to be scaled uniformly to fit inside the box (i.e. "meet" and not "clip"), and for an image which is smaller to be displayed at its native size. (It should also be centered, but I've figured that part out.)
It's been easy to get large images to scale down, but I haven't figured out how to get small images to not scale up. Any ideas? It's a similar problem to this question but for SVG instead of CSS. This other question is definitely related, but because I don't know the pixel sizes of the images in advance the solution doesn't help me.
Here's a simplified version of the current SVG structure, with a Placekitten as a background image:
<svg xmlns="http://www.w3.org/2000/svg" id="svgroot" xlinkns="http://www.w3.org/1999/xlink" width="640" height="480" x="640" y="480" overflow="visible">
<svg id="canvasBackground" width="640" height="480" x="0" y="0" overflow="none" style="pointer-events:none">
<rect width="100%" height="100%" x="0" y="0" stroke="#000" fill="#FFF" style="pointer-events:none"/>
<image id="background_image" width="100%" height="100%" preserveAspectRatio="xMidYMid" style="pointer-events:none" href="http://placekitten.com/500/400/"/>
</svg>
</svg>