Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent browser anti-aliasing when upscaling?

With Google's Chart Image API (which was unfortunately deprecated April 2012), you can generate QR codes.

QR code

I'm sure I can change the size of the resulting image using the API, but I'd rather just use CSS and the width and height properties to make it a little bigger.
In Chrome at least, this results in nasty anti-aliasing (not preferable, since it needs to be parsable by machines). Is there a way to tell browsers not to anti-alias upscaled images?

like image 711
Protector one Avatar asked Nov 28 '25 08:11

Protector one


1 Answers

This guy has the solution: http://nullsleep.tumblr.com/post/16417178705/how-to-disable-image-smoothing-in-modern-web-browsers

img { 
    image-rendering: optimizeSpeed;             /* PREFER SPEED OVER SMOOTHING  */
    image-rendering: -moz-crisp-edges;          /* Firefox                        */
    image-rendering: -o-crisp-edges;            /* Opera                          */
    image-rendering: -webkit-optimize-contrast; /* Chrome (and eventually Safari) */
    image-rendering: optimize-contrast;         /* CSS3 Proposed                  */
    -ms-interpolation-mode: nearest-neighbor;   /* IE8+                           */
  }

Sooo for you:

imgQR { 
    width:100px;
    height:100px;
    image-rendering: optimizeSpeed;             /* PREFER SPEED OVER SMOOTHING  */
    image-rendering: -moz-crisp-edges;          /* Firefox                        */
    image-rendering: -o-crisp-edges;            /* Opera                          */
    image-rendering: -webkit-optimize-contrast; /* Chrome (and eventually Safari) */
    image-rendering: optimize-contrast;         /* CSS3 Proposed                  */
    -ms-interpolation-mode: nearest-neighbor;   /* IE8+                           */
  }
like image 109
Brian Avatar answered Nov 30 '25 22:11

Brian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!