Proposals/Auto-sized image

From SVG
Jump to: navigation, search

This is a proposal for the "Auto-sized image" SVG2 Requirement.

I think we can take two approaches here.

Proposal 1: We redefine the lacuna value of the width="" and height="" attributes to mean "automatic based on the intrinsic size of the image". For example when referencing a 150x100 PNG:

<image href="a.png"/>

would be equivalent to

<image href="a.png" width="150" height="100"/>

in terms of rendering behaviour, and

<image href="a.png" width="300"/>

would be equivalent to

<image href="a.png" width="300" height="200"/>

This parallels the behaviour of <img> in HTML.

In the SVG DOM, we can treat this like other attributes that have "computed" lacuna values, i.e. the SVGLength value will reflect the computed value and if the SVGLength is modified then the DOM attribute is set on the element.

This breaks the current behaviour of omitted attributes being the same as 0, which some people might be relying on.

Proposal 2: We introduce another attribute to set the sizing mode of the image. For example:

<image href="a.png" size="intrinsic"/>

would use the intrinsic size of the image, and as above if one dimension is specified the other is determined based on the aspect ratio of the image:

<image href="a.png" width="300" size="intrinsic"/>