<image> - SVG: Scalable Vector Graphics 编辑

The <image> SVG element includes images inside SVG documents. It can display raster image files or other SVG files.

The only image formats SVG software must support are JPEG, PNG, and other SVG files. Animated GIF behavior is undefined.

SVG files displayed with <image> are treated as an image: external resources aren't loaded, :visited styles aren't applied, and they cannot be interactive. To include dynamic SVG elements, try <use> with an external URL. To include SVG files and run scripts inside them, try <object> inside of <foreignObject>.

Note: The HTML spec defines <image> as a synonym for <img> while parsing HTML. This specific element and its behavior only apply inside SVG documents or inline SVG.

Usage context

CategoriesGraphics element, Graphics referencing element
Permitted contentAny number of the following elements, in any order:
Animation elements
Descriptive elements

Attributes

Global attributes

Specific attributes

  • x: Positions the image horizontally from the origin.
  • y: Positions the image vertically from the origin.
  • width: The width the image renders at. Unlike HTML's <img>, this attribute is required.
  • height: The height the image renders at. Unlike HTML's <img>, this attribute is required.
  • href and xlink:href: Points at a URL for the image file.
  • preserveAspectRatio: Controls how the image is scaled.

DOM Interface

<image> implements the SVGImageElement interface.

Example

Basic rendering of a PNG image in SVG:

SVG

<svg width="200" height="200"
  xmlns="http://www.w3.org/2000/svg">
  <image href="https://www.wenjiangs.com/wp-content/uploads/2020/mozilla/mdn_logo_only_color.png" height="200" width="200"/>
</svg>

Result

Specifications

SpecificationStatusComment
Scalable Vector Graphics (SVG) 2
The definition of '<image>' in that specification.
Candidate RecommendationAllows omitting height and width
Scalable Vector Graphics (SVG) 1.1 (Second Edition)
The definition of '<image>' in that specification.
RecommendationInitial definition

Browser compatibility

BCD tables only load in the browser

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:49 次

字数:6482

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文