Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image scaling by CSS: is there a webkit alternative for -moz-crisp-edges?

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?

like image 700
Martin Kool Avatar asked Oct 10 '10 13:10

Martin Kool


People also ask

Can you scale an image in CSS?

Use the object-fit Property to Resize the Image in CSS We can use the object-fit property in CSS to resize the image to fit its container. A container may be larger or smaller in size than the image. The property lets us fit the image or videos according to the size of the container.

How do I make an image scale proportionally CSS?

A common use is to set max-width: 100%; height: auto; so large images don't exceed their containers width. Another way is the use of object-fit property, this will fit image, without changing the proportionally.

How do you scale proportionally in CSS?

For proportional resizing purposes, it makes matters extremely simple: Define the width of an element as a percentage (eg: 100%) of the parent's width, then define the element's padding-top (or -bottom) as a percentage so that the height is the aspect ratio you need. And that's it!

How do you scale an image to fit the screen in CSS?

Using CSS, you can set the background-size property for the image to fit the screen (viewport). The background-size property has a value of cover . It instructs browsers to automatically scale the width and height of a responsive background image to be the same or bigger than the viewport.


1 Answers

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+           */ } 
like image 122
Phrogz Avatar answered Sep 20 '22 04:09

Phrogz