image-rendering
CSS
property sets an image scaling algorithm. The property applies to an element itself, to any images set in its other properties, and to its descendants.
用户代理
will scale an image when the page author specifies dimensions other than its natural size. Scaling may also occur due to user interaction (zooming). For example, if the natural size of an image is
100×100px
,
but its actual dimensions are
200×200px
(或
50×50px
), then the image will be upscaled (or downscaled) using the algorithm specified by
image-rendering
. This property has no effect on non-scaled images.
/* Keyword values */ image-rendering: auto; image-rendering: crisp-edges; image-rendering: pixelated; /* Global values */ image-rendering: inherit; image-rendering: initial; image-rendering: unset;
auto
smooth
The image should be scaled with an algorithm that maximizes the appearance of the image. In particular, scaling algorithms that "smooth" colors are acceptable, such as bilinear interpolation. This is intended for images such as photos.
high-quality
smooth
, but with a preference for higher-quality scaling. If system resources are constrained, images with
high-quality
should be prioritized over those with any other value, when considering which images to degrade the quality of and to what degree.
crisp-edges
pixelated
auto
.
注意:
The values
optimizeQuality
and
optimizeSpeed
present in an early draft (and coming from its SVG counterpart
image-rendering
) are defined as synonyms for the
smooth
and
pixelated
values respectively.
| 初始值 |
auto
|
|---|---|
| 适用于 | 所有元素 |
| 继承 | yes |
| 计算值 | 如指定 |
| 动画类型 | discrete |
auto | crisp-edges | pixelated
In practical use, the
pixelated
and
crisp-edges
rules can be combined to provide some fallback for each other. (Just prepend the actual rules with the fallback.) The
画布 API
can provide a
fallback solution for
pixelated
through manual image data manipulation or with
imageSmoothingEnabled
.
<div> <img class="auto" alt="auto" src="https://yari-demos.prod.mdn.mozit.cloud/files/2765/blumen.jpg" /> <img class="pixelated" alt="pixelated" src="https://yari-demos.prod.mdn.mozit.cloud/files/2765/blumen.jpg" /> <img class="crisp-edges" alt="crisp-edges" src="https://yari-demos.prod.mdn.mozit.cloud/files/2765/blumen.jpg" /> </div>
img {
height: 200px;
}
.auto {
image-rendering: auto;
}
.pixelated {
-ms-interpolation-mode: nearest-neighbor;
image-rendering: pixelated;
}
.crisp-edges {
image-rendering: -webkit-optimize-contrast;
image-rendering: crisp-edges;
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
CSS Images Module Level 3
The definition of 'image-rendering' in that specification. |
候选推荐 | 初始定义。 |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
image-rendering
|
Chrome 完整支持 13 | Edge 完整支持 79 | Firefox 完整支持 3.6 | IE 不支持 No | Opera 完整支持 15 | Safari 完整支持 6 | WebView Android 完整支持 ≤37 | Chrome Android 完整支持 18 | Firefox Android 完整支持 4 | Opera Android 完整支持 14 | Safari iOS 完整支持 6 | Samsung Internet Android 完整支持 1.0 |
crisp-edges
|
Chrome
完整支持
13
Alternate Name
|
Edge
完整支持
79
Alternate Name
|
Firefox
完整支持
65
|
IE 不支持 No |
Opera
完整支持
15
Alternate Name
|
Safari
完整支持
6
Alternate Name
|
WebView Android
完整支持
≤37
Alternate Name
|
Chrome Android
完整支持
18
Alternate Name
|
Firefox Android
完整支持
65
|
Opera Android
完整支持
14
Alternate Name
|
Safari iOS
完整支持
6
Alternate Name
|
Samsung Internet Android
完整支持
1.0
Alternate Name
|
optimizeQuality
弃用
非标
|
Chrome 完整支持 28 | Edge 完整支持 79 | Firefox 完整支持 3.6 | IE 不支持 No | Opera 完整支持 15 | Safari 完整支持 6.1 | WebView Android 完整支持 ≤37 | Chrome Android 完整支持 28 | Firefox Android 完整支持 4 | Opera Android 完整支持 14 | Safari iOS 完整支持 7 | Samsung Internet Android 完整支持 1.5 |
optimizeSpeed
弃用
非标
|
Chrome 完整支持 28 | Edge 完整支持 79 | Firefox 完整支持 3.6 | IE 不支持 No | Opera 完整支持 15 | Safari 完整支持 6.1 | WebView Android 完整支持 ≤37 | Chrome Android 完整支持 28 | Firefox Android 完整支持 4 | Opera Android 完整支持 14 | Safari iOS 完整支持 7 | Samsung Internet Android 完整支持 1.5 |
pixelated
|
Chrome 完整支持 41 | Edge 完整支持 79 | Firefox 不支持 No | IE 不支持 No | Opera 完整支持 26 | Safari 完整支持 10 | WebView Android 完整支持 41 | Chrome Android 完整支持 41 | Firefox Android 不支持 No | Opera Android 完整支持 26 | Safari iOS 完整支持 10 | Samsung Internet Android 完整支持 4.0 |
完整支持
不支持
非标。预期跨浏览器支持较差。
弃用。不要用于新网站。
使用非标名称。
要求使用供应商前缀或不同名称。
注意:
Although
crisp-edges
is supposed to use a pixel-art scaler like in the specification example, in practice no browsers (as of January 2020) does so.
In Firefox
,
crisp-edges
is interpreted as nearest-neighbor,
pixelated
is not supported, and
auto
is interpolated as trilinear or linear.
For behavior on Chromium and Safari (WebKit), see the
GetInterpolationQuality
function and
CSSPrimitiveValue::operator ImageRendering()
分别。
object-fit
,
object-position
,
image-orientation
,
image-rendering
,
image-resolution
.
<gradient>
<image>
image-orientation
image-rendering
object-fit
object-position