通过 CSS 进行图像缩放:是否有 -moz-crisp-edges 的 webkit 替代品?

发布于 2024-09-27 04:27:04 字数 255 浏览 3 评论 0原文

我有一张像素为 100x100 的图像。我想显示它两倍的大小,所以 200x200,我想通过 CSS 来完成它,而不是通过服务器(明确地)。

几年以来,所有浏览器都对图像进行了抗锯齿处理,而不是按像素缩放。

Mozilla 允许指定算法: image-rendering: -moz-crisp-edges; IE 也是如此:-ms-interpolation-mode:nearest-neighbor;

有任何已知的 webkit 替代品吗?

I have an image that is 100x100 in pixels. I want to show it twice the size, so 200x200 and I want to do it by CSS and (explicitly) not by the server.

Since a few years, images get anti-aliased by all browsers instead of doing a by-pixel scale.

Mozilla allows to specify the algorithm: image-rendering: -moz-crisp-edges;
So does IE: -ms-interpolation-mode: nearest-neighbor;

Any known webkit alternative?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ぺ禁宫浮华殁 2024-10-04 04:27:04

WebKit 现在支持 CSS 指令:

image-rendering:-webkit-optimize-contrast;

您可以使用 Chrome 和此页面上的最后一个图像来查看它的实际工作情况:
http://phrogz.net/tmp/canvas_image_zoom.html

该页面使用的规则是:

.pixelated {
  image-rendering:optimizeSpeed;             /* Legal fallback */
  image-rendering:-moz-crisp-edges;          /* Firefox        */
  image-rendering:-o-crisp-edges;            /* Opera          */
  image-rendering:-webkit-optimize-contrast; /* Safari         */
  image-rendering:optimize-contrast;         /* CSS3 Proposed  */
  image-rendering:crisp-edges;               /* CSS4 Proposed  */
  image-rendering:pixelated;                 /* CSS4 Proposed  */
  -ms-interpolation-mode:nearest-neighbor;   /* IE8+           */
}

WebKit now supports the CSS directive:

image-rendering:-webkit-optimize-contrast;

You can see it working in action using Chrome and the last image on this page:
http://phrogz.net/tmp/canvas_image_zoom.html

The rules used on that page are:

.pixelated {
  image-rendering:optimizeSpeed;             /* Legal fallback */
  image-rendering:-moz-crisp-edges;          /* Firefox        */
  image-rendering:-o-crisp-edges;            /* Opera          */
  image-rendering:-webkit-optimize-contrast; /* Safari         */
  image-rendering:optimize-contrast;         /* CSS3 Proposed  */
  image-rendering:crisp-edges;               /* CSS4 Proposed  */
  image-rendering:pixelated;                 /* CSS4 Proposed  */
  -ms-interpolation-mode:nearest-neighbor;   /* IE8+           */
}
謌踐踏愛綪 2024-10-04 04:27:04

不幸的是,WebKit 中似乎没有这个功能。请参阅最近的错误报告:

https://bugs.webkit.org/show_bug.cgi?id =40881

Unfortunately, it looks like this feature is absent in WebKit. See this recent bug report:

https://bugs.webkit.org/show_bug.cgi?id=40881

記憶穿過時間隧道 2024-10-04 04:27:04

除了@Phrogz非常有用的答案之外,在阅读完本文后: https:// developer.mozilla.org/en-US/docs/CSS/image-rendering

似乎最好的 CSS 是这样的:

image-rendering:optimizeSpeed;              /* Legal fallback                 */
image-rendering:-moz-crisp-edges;           /* Firefox                        */
image-rendering:-o-crisp-edges;             /* Opera                          */
image-rendering:-webkit-optimize-contrast;  /* Chrome (and eventually Safari) */
image-rendering:crisp-edges;                /* CSS3 Proposed                  */
-ms-interpolation-mode:bicubic;             /* IE8+                           */

In addition to @Phrogz very useful answer and after reading this: https://developer.mozilla.org/en-US/docs/CSS/image-rendering

It seems like the best CSS would be this:

image-rendering:optimizeSpeed;              /* Legal fallback                 */
image-rendering:-moz-crisp-edges;           /* Firefox                        */
image-rendering:-o-crisp-edges;             /* Opera                          */
image-rendering:-webkit-optimize-contrast;  /* Chrome (and eventually Safari) */
image-rendering:crisp-edges;                /* CSS3 Proposed                  */
-ms-interpolation-mode:bicubic;             /* IE8+                           */
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文