|
|
Donner 0.5.1
Embeddable browser-grade SVG2 engine
|
<feImage> imports an external image — or a fragment of the current document — into the filter graph as an additional input.
It's how you use a photograph as a lighting source, mask, or displacement map, or how you reuse an existing SVG element's rendering as an input to another primitive like "<feDisplacementMap>" or "<feComposite>".
Conceptually, <feImage> is a tiny "load this picture into the filter canvas" primitive. It doesn't take a filter input (no in attribute); instead, its source is pointed at by the href attribute. The result fills the primitive subregion at the <feImage>'s x, y, width, height, and downstream primitives can use it just like any other input.
The href attribute accepts either:
When the source image's aspect ratio doesn't match the destination rectangle (the filter primitive subregion), preserveAspectRatio decides whether to stretch, letterbox, or crop the image so that it fits.
The attribute is a pair: <align> <meetOrSlice>.
The default is xMidYMid meet.
The diagram below shows the same square source image fitted into a wider landscape destination rectangle under meet, slice, and none. The dashed box is the destination; the shaded area shows where the image pixels actually land:
The simplest use of <feImage>: load an external PNG and output it as the filter result. The filter completely replaces the source graphic with the loaded image. In practice you'd usually combine it with a compositing primitive to mix it with the source:
href="#star" points at another element in the same document. The filter re-renders that element into its own bounding box and uses those pixels as the filter output. This is a handy way to reuse a shape (or a group of shapes) as input to a downstream primitive without duplicating geometry:
Here <feImage> produces a gradient, which is then fed to <feDisplacementMap> as the displacement source. The gradient's red and green channels push the source graphic's pixels around, producing a warp. This is a common pattern for effects that need a custom "map" input (lighting normals, displacement fields, texture lookups):
| Attribute | Default | Description |
|---|---|---|
| href | (none) | URL or in-document fragment reference (#id) for the source image. |
| preserveAspectRatio | xMidYMid meet | How the source is fitted into the primitive subregion when aspect ratios differ. See above. |
| crossorigin | (none) | CORS setting for external URL loads (anonymous or use-credentials). |
Inherits standard filter primitive attributes (in, result, x, y, width, height) from donner::svg::SVGFilterPrimitiveStandardAttributes.