mozilla

Revision 10345 of image-rendering

  • Revision slug: CSS/Image-rendering
  • Revision title: image-rendering
  • Revision id: 10345
  • Created:
  • Creator: brianblakely
  • Is current revision? No
  • Comment 16 words added, 13 words removed

Revision Content

{{ CSSRef() }}

Summary

The image-rendering CSS property provides a hint to the user agent about how to handle its image rendering.
image-rendering applies to scaled images (and other elements, see below). For example, if the natural size of the image is 100×100px but the page author specifies the dimensions to 200×200px (or50×50px), then the image will be upscaled (or downscaled) to the new dimensions using the specified algorithm. Scaling may also apply due to user interaction (zooming).

<style type="text/css"></style>
  • {{ Xref_cssinitial() }}: {{ Cssxref("auto") }}
  • Applies to:
    • images
    • background-images of any element
    • HTML5  {{ HTMLElement("video") }} Element
    • HTML5 {{ HTMLElement("canvas") }} Element
  • {{ Xref_cssinherited() }}: yes
  • Media: {{ Xref_cssvisual() }}
  • {{ Xref_csscomputed() }}: as specified

Syntax

image-rendering:  auto | inherit | optimizeSpeed | optimizeQuality | -moz-crisp-edges | -o-crisp-edges 

Values

auto
Default value, depends on the user agent. Since version 1.9 (Firefox 3.0), Gecko uses bilinear resampling (high quality).
optimizeQuality
Indicates that the user agent shall emphasize quality over rendering speed. Gecko uses bilinear resampling (high quality).
optimizeSpeed
The user agent should use a resampling algorithm which achieves the goal of fast rendering. Currently Gecko (Firefox) uses nearest neighbor resampling (low quality).
-moz-crisp-edges | -o-crisp-edges
Mozilla extension. Gecko (Firefox) always uses nearest neighbor resampling (low quality). Use this value to avoid upscaled images with sharp edges getting blurry. {{ bug("423756") }}.
-webkit-optimize-contrast
WebKit extension ({{ webkitbug("56627") }}). WebKit uses a pixelation-generating resampling. The algorithm for now seems to be nearest-neighbor, but this can be WebKit-port specific, and there are other algorithms that can be used as well. Use this value to avoid upscaled images with sharp edges getting blurry.
  • Currently auto and optimizeQuality are equal by default, both result in bilinear resampling.
  • Currently optimizeSpeed and -moz-crisp-edges are equal, both result in nearest neighbor resampling.
  • Warning: Unlike the gecko rendering engine, optimizeSpeed and -webkit-optimize-contrast do not mean the same thing in WebKit.

Examples

img  { 
       image-rendering: optimizeQuality;  /* Firefox 3.6+; default behavior is identical, no need to specify */
       -ms-interpolation-mode: bicubic;   /* Internet Explorer 7.0; default in IE8+ */
     }
/* applies to GIF and PNG images; avoids blurry edges */

img[src$=".gif"], img[src$=".png"] {

                   image-rendering: -moz-crisp-edges;         /* Firefox */
                   -ms-interpolation-mode: nearest-neighbor;  /* IE */
                 }
html  { image-rendering: -moz-crisp-edges; }        /* all images, videos, background-images */
img   { -ms-interpolation-mode: nearest-neighbor; } /* all images, IE */
div { 
        background: url(chessboard.gif) no-repeat 50% 50%;
        image-rendering: -moz-crisp-edges;
}
video { image-rendering: optimizeSpeed; }

Live Examples

image-rendering:optimizeQuality; -ms-interpolation-mode:bicubic;
78%squares.gif 100%squares.gif 138%squares.gif downsizedhut.jpg upsizedblumen.jpg

image-rendering:-moz-crisp-edges; image-rendering: -o-crisp-edges; image-rendering:-webkit-optimize-contrast; -ms-interpolation-mode:nearest-neighbor;
78%squares.gif 100%squares.gif 138%squares.gif downsizedhut.jpg upsizedblumen.jpg

Notes

  • {{ bug("486918") }} (Awful image quality in downscaling)

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support

image-rendering: auto | -webkit-optimize-contrast

3.6 (1.9.2)
image-rendering
7.0
-ms-interpolation-mode: bicubic | nearest-neighbor
  • applies only to images (JPG, GIF, PNG, ...)
  • in IE7 only for images without transparency
  • does not inherit
  • default value IE7: nearest-neighbor (low quality)
  • default value IE8+: bicubic    (high quality)

11.60

image-rendering: auto | -o-crisp-edges | optimizeSpeed | optimizeQuality

6533.21.1, r86920

image-rendering: auto | optimizeSpeed | optimizeQuality | -webkit-optimize-contrast

  • -webkit-optimize-contrast is similar to -moz-crisp-edges, in that it selects the pixelation algorithm over the blurry algorithm for scaling. Pixelated scaling algorithm for now seems to be nearest-neighbor.
  • -webkit-optimize-contrast implemented in the WebKit nightlies as of May 20th, 2011.
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }}

See also  Microsoft MSDN -ms-interpolation-mode property

Canvas can provide a fallback solution for crisp-edge/optimize-contrast through manual imageData manipulation.

Specifications

image-rendering is an SVG property, it is not defined in any CSS standard. Gecko (Firefox)and Presto (Opera) apply it also to HTML and XML content.

SVG 1.1 Painting #image-rendering

{{ languages( { "ja": "ja/CSS/image-rendering"} ) }}

Revision Source

<div>{{ CSSRef() }}</div>
<h2>Summary</h2>
<p>The <code>image-rendering</code> <a href="/en/CSS" title="CSS">CSS</a> property provides a hint to the user agent about how to handle its image rendering.<br> <code>image-rendering </code>applies to scaled images (and other elements, see below). For example, if the natural size of the image is<em> 100×100px </em>but the page author specifies the dimensions to <code>200×200px</code> (or<code>50×50px</code>), then the image will be upscaled (or downscaled) to the new dimensions using the specified algorithm. Scaling may also apply due to user interaction (zooming).</p>
<nobr>
&lt;style type="text/css"&gt;<!--[CDATA[.cssprop {
  display:table;
  padding: 0.4em;
  border-left:0.15em solid;
  background-color:#eeeeff
}
.cssprop li {
 display:table-row;
 padding: 3px;
 margin:0;
}
.cssprop li dfn {
  display:table-cell;
  padding: 0 5px;
  border-bottom: none;
  cursor:inherit;
}


]]-->&lt;/style&gt;
<ul class="cssprop"> <li><dfn>{{ Xref_cssinitial() }}:</dfn> {{ Cssxref("auto") }}</li> <li><dfn>Applies to:</dfn> <ul> <li style="display:list-item; list-style-type:disc">images</li> <li style="display:list-item; list-style-type:disc">background-images of any element</li> <li style="display:list-item; list-style-type:disc">HTML5  {{ HTMLElement("video") }} Element</li> <li style="display:list-item; list-style-type:disc">HTML5 {{ HTMLElement("canvas") }} Element</li> </ul> </li> <li><dfn>{{ Xref_cssinherited() }}:</dfn> yes</li> <li><dfn>Media:</dfn> {{ Xref_cssvisual() }}</li> <li><dfn>{{ Xref_csscomputed() }}:</dfn> as specified</li>
</ul>
</nobr>
<h2>Syntax</h2>
<pre>image-rendering:  auto | inherit | optimizeSpeed | optimizeQuality | -moz-crisp-edges | -o-crisp-edges </pre>
<h3>Values</h3>
<dl> <dt><strong>auto</strong></dt> <dd>Default value, depends on the user agent. Since version 1.9 (Firefox 3.0), Gecko uses<em> bilinear </em>resampling (high quality).</dd> <dt><strong>optimizeQuality</strong></dt> <dd>Indicates that the user agent shall emphasize quality over rendering speed. Gecko uses<em> bilinear </em>resampling (high quality).</dd> <dt><strong>optimizeSpeed</strong></dt> <dd>The user agent should use a resampling algorithm which achieves the goal of fast rendering. Currently Gecko (Firefox) uses<em> nearest neighbor </em>resampling (low quality).</dd> <dt><strong>-moz-crisp-edges</strong> | <strong>-o-crisp-edges</strong></dt> <dd><a class="internal" href="/en/CSS/CSS_Reference/Mozilla_Extensions" title="en/CSS Reference/Mozilla Extensions">Mozilla extension</a>. Gecko (Firefox) always uses <em>nearest neighbor</em> resampling (low quality). Use this value to avoid upscaled images with sharp edges getting blurry. {{ bug("423756") }}.</dd> <dt><strong>-webkit-optimize-contrast</strong></dt> <dd>WebKit extension ({{ webkitbug("56627") }}). WebKit uses a pixelation-generating resampling. The algorithm for now seems to be nearest-neighbor, but this can be WebKit-port specific, and there are other algorithms that can be used as well. Use this value to avoid upscaled images with sharp edges getting blurry.</dd>
</dl>
<div class="note"> <ul style="margin:0;padding:0 0 0 1em;"> <li>Currently<code> auto </code>and<code> optimizeQuality </code>are equal by default, both result in <em>bilinear</em> resampling.</li> <li>Currently<code> optimizeSpeed </code>and<code> -moz-crisp-edges </code>are equal, both result in <em>nearest neighbor</em> resampling.</li> <li> <p>Warning: Unlike the gecko rendering engine, <code>optimizeSpeed </code>and <code>-webkit-optimize-contrast<strong> do not mean the same thing </strong> in WebKit.</code></p> </li> </ul>
</div>
<h2>Examples</h2>
<pre>img  { 
       image-rendering: optimizeQuality;  /* Firefox 3.6+; default behavior is identical, no need to specify */
       -ms-interpolation-mode: bicubic;   /* Internet Explorer 7.0; default in IE8+ */
     }</pre>
<pre>/* applies to GIF and PNG images; avoids blurry edges */

img[src$=".gif"], img[src$=".png"] {

                   image-rendering: -moz-crisp-edges;         /* Firefox */
                   -ms-interpolation-mode: <code>nearest-neighbor</code>;  /* IE */
                 }</pre>
<pre>html  { image-rendering: -moz-crisp-edges; }        /* all images, videos, background-images */
img   { -ms-interpolation-mode: <code>nearest-neighbor</code>; } /* all images, IE */
</pre>
<pre>div { 
        background: url(chessboard.gif) no-repeat 50% 50%;
        image-rendering: -moz-crisp-edges;
}</pre>
<pre>video { image-rendering: optimizeSpeed; }</pre>
<h3>Live Examples</h3>
<p style="image-rendering: optimizequality;"><code>image-rendering:optimizeQuality; -ms-interpolation-mode:bicubic;</code><br> 78%<img alt="squares.gif" src="/@api/deki/files/3612/=squares.gif" style="width: 39px; height: 39px;"> 100%<img alt="squares.gif" src="/@api/deki/files/3612/=squares.gif" style="width: 50px; height: 50px;"> 138%<img alt="squares.gif" src="/@api/deki/files/3612/=squares.gif" style="width: 69px; height: 69px;"> downsized<img alt="hut.jpg" src="/@api/deki/files/3613/=hut.jpg" style="width: 89px; height: 89px;"> upsized<img alt="blumen.jpg" src="/@api/deki/files/3611/=blumen.jpg" style="width: 77px; height: 89px;"></p>
<p style="image-rendering: -moz-crisp-edges; image-rendering: -o-crisp-edges; image-rendering: -webkit-optimize-contrast; -ms-interpolation-mode: nearest-neighbor"><code>image-rendering:-moz-crisp-edges; image-rendering: -o-crisp-edges; image-rendering:-webkit-optimize-contrast; -ms-interpolation-mode:nearest-neighbor;</code><br> 78%<img alt="squares.gif" src="/@api/deki/files/3612/=squares.gif" style="width: 39px; height: 39px;"> 100%<img alt="squares.gif" src="/@api/deki/files/3612/=squares.gif" style="width: 50px; height: 50px;"> 138%<img alt="squares.gif" src="/@api/deki/files/3612/=squares.gif" style="width: 69px; height: 69px;"> downsized<img alt="hut.jpg" src="/@api/deki/files/3613/=hut.jpg" style="width: 89px; height: 89px;"> upsized<img alt="blumen.jpg" src="/@api/deki/files/3611/=blumen.jpg" style="width: 77px; height: 89px;"></p>
<h3>Notes</h3>
<ul> <li>{{ bug("486918") }} (Awful image quality in downscaling)</li>
</ul>
<h2 name="Browser_Compatibility">Browser compatibility</h2>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Chrome</th> <th>Firefox (Gecko)</th> <th>Internet Explorer</th> <th>Opera</th> <th>Safari (WebKit)</th> </tr> <tr> <td>Basic support</td> <td> <p>image-rendering: auto | -webkit-optimize-contrast</p> </td> <td>3.6 (1.9.2)<br> <!-- br--><code>image-rendering</code></td> <td>7.0<br> <code>-ms-interpolation-mode: bicubic | nearest-neighbor</code> <ul style="margin-top:1em;margin-bottom:0"> <li>applies only to images (JPG, GIF, PNG, ...)</li> <li>in IE7 only for images without transparency</li> <li>does not inherit</li> <li>default value IE7:<code> nearest-neighbor </code>(low quality)</li> <li>default value IE8+:<code> bicubic    </code>(high quality)</li> </ul> </td> <td> <p>11.60</p> <p><code>image-rendering: auto | -o-crisp-edges | optimizeSpeed | optimizeQuality</code></p> </td> <td> <p>6533.21.1, r86920</p> <p><code>image-rendering: auto | optimizeSpeed | optimizeQuality | -webkit-optimize-contrast</code></p> <ul> <li>-webkit-optimize-contrast is similar to -moz-crisp-edges, in that it selects the pixelation algorithm over the blurry algorithm for scaling. Pixelated scaling algorithm for now seems to be nearest-neighbor.</li> <li>-webkit-optimize-contrast implemented in the WebKit nightlies as of May 20th, 2011.</li> </ul> </td> </tr> </tbody> </table>
</div>
<div id="compat-mobile"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Android</th> <th>Firefox Mobile (Gecko)</th> <th>IE Phone</th> <th>Opera Mobile</th> <th>Safari Mobile</th> </tr> <tr> <td>Basic support</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> </tr> </tbody> </table>
</div>
<p>See also  <a class="external" href="http://msdn.microsoft.com/en-us/library/ff521095(VS.85).aspx" title="http://msdn.microsoft.com/en-us/library/ff521095(VS.85).aspx">Microsoft MSDN<code> -ms-interpolation-mode </code>property</a></p>
<p>Canvas can provide a <a class="external" href="http://phrogz.net/tmp/canvas_image_zoom.html" title="http://phrogz.net/tmp/canvas_image_zoom.html">fallback solution for crisp-edge/optimize-contrast</a> through manual imageData manipulation.</p>
<h2>Specifications</h2>
<p><code>image-rendering </code>is an SVG property, it is not defined in any CSS standard. Gecko (Firefox)and Presto (Opera) apply it also to HTML and XML content.</p>
<p><a class="external" href="http://www.w3.org/TR/SVG/painting.html#ImageRenderingProperty" title="http://www.w3.org/TR/SVG/painting.html#ImageRenderingProperty">SVG 1.1 Painting #image-rendering</a></p>
<p>{{ languages( { "ja": "ja/CSS/image-rendering"} ) }}</p>
Revert to this revision