Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<title>preserveAspectRatio slice on an image element crops a referenced SVG</title>
<link rel="author" title="Sam Weinig" href="mailto:sam@webkit.org">
<link rel="match" href="image-preserveaspectratio-slice-svg-ref.html">
<meta name="assert" content="With xMaxYMax slice, a square SVG fitted to a 200x100 rectangle is scaled to 200x200 and aligned to the bottom, so only its bottom half, which is green, is visible. Rendering the whole SVG inside the rectangle instead would show its top half, which is red.">
<style>
body { margin: 0; }
</style>
<!-- Red is painted where the image must be, so an image drawn anywhere else, or not cropped, leaves red showing. -->
<svg width="220" height="120">
<rect x="10" y="10" width="200" height="100" fill="red"/>
<image x="10" y="10" width="200" height="100" preserveAspectRatio="xMaxYMax slice" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' viewBox='0 0 100 100'><rect width='100' height='50' fill='red'/><rect y='50' width='100' height='50' fill='rgb(0,128,0)'/></svg>"/>
</svg>