Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6985297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:39:44+00:00 2026-05-27T18:39:44+00:00

So I ran across this recently: http://www.nicalis.com/ And I was curious: Is there a

  • 0

So I ran across this recently: http://www.nicalis.com/

And I was curious: Is there a way to do this sort of thing with smaller images? I mean, it’s pixel art, and rather than using an image with each pixel quadrupled in size couldn’t we stretch them with the code? So I started trying to make it happen.

I tried CSS, Javascript, and even HTML, none of which worked. They all blur up really badly (like this: http://jsfiddle.net/nUVJt/2/), which brings me to my question: Can you stretch an image in-browser without any antialiasing?

I’m open to any suggestions, whether it’s using a canvas, jQuery, CSS3, or whatever.

Thanks for the help!

EDIT: There’s a better way to do this now! A slightly less hackish way! Here’s the magic:

.pixelated {
    image-rendering: -moz-crisp-edges;
    image-rendering: -o-crisp-edges;
    image-rendering: -webkit-optimize-contrast;
    -ms-interpolation-mode: nearest-neighbor;
    image-rendering: pixelated;
}

And that’ll stop the anti-aliasing in all the modern browsers. It’ll even work in IE7-8, but not in 9, and I don’t know of any way of doing it in 9, unfortunately (aside from the canvas hack outlined below).
It’s not even funny how much faster it is doing it this way than with JS. Here’s more info on those: https://developer.mozilla.org/en-US/docs/CSS/Image-rendering

EDIT2: Because this isn’t an official spec yet, it’s not very reliable. Chrome and FF both seem to have stopped supporting it since I wrote the above (according to this article which was mentioned below), which is really annoying. We’re probably going to have to wait a few more years before we really can start using this in CSS, which is really unfortunate.

FINAL EDIT: There is an official way to do this now! There’s a new property called image-rendering. It’s in the CSS3 spec. Support is super spotty right now, but Chrome just added support so before too long we’ll be able to just say image-rendering: pixelated; and it’ll work all the places (yaayy evergreen browsers!)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:39:44+00:00Added an answer on May 27, 2026 at 6:39 pm

    The Canvas documentation explicitly does not specify a scaling method – in my own tests it did indeed anti-alias the image quite badly in Firefox.

    The code below copies pixel by pixel from a source image (which must be from the same Origin or from a Data URI) and scales it by the specified factor.

    An extra off-screen canvas (src_canvas) is required to receive the original source image, and its image data is then copied pixel by pixel into an on-screen canvas.

    var img = new Image();
    img.src = ...;
    img.onload = function() {
    
        var scale = 8;
    
        var src_canvas = document.createElement('canvas');
        src_canvas.width = this.width;
        src_canvas.height = this.height;
    
        var src_ctx = src_canvas.getContext('2d');
        src_ctx.drawImage(this, 0, 0);
        var src_data = src_ctx.getImageData(0, 0, this.width, this.height).data;
    
        var dst_canvas = document.getElementById('canvas');
        dst_canvas.width = this.width * scale;
        dst_canvas.height = this.height * scale;
        var dst_ctx = dst_canvas.getContext('2d');
    
        var offset = 0;
        for (var y = 0; y < this.height; ++y) {
            for (var x = 0; x < this.width; ++x) {
                var r = src_data[offset++];
                var g = src_data[offset++];
                var b = src_data[offset++];
                var a = src_data[offset++] / 100.0;
                dst_ctx.fillStyle = 'rgba(' + [r, g, b, a].join(',') + ')';
                dst_ctx.fillRect(x * scale, y * scale, scale, scale);
            }
        }
    };
    

    Working demo at http://jsfiddle.net/alnitak/LwJJR/

    EDIT a more optimal demo is available at http://jsfiddle.net/alnitak/j8YTe/ that also uses a raw image data array for the destination canvas.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ran across this recently and wondering if someone out there can give me a
I have been familiarizing myself with javascript closures and ran across this article http://blog.morrisjohns.com/javascript_closures_for_dummies.html
I ran across this very nice jQuery/bootstrap modal plugin: http://nikku.github.com/jquery-bootstrap-scripting/ However, in trying to
I ran across this issue and am wondering if there is a better way
I recently ran across this puzzle, was finally able to struggle out a hacky
I recently ran across this great article by Chad Parry entitled DIY-DI or Do-It-Yourself
I recently ran across a routine that looks something like this: procedure TMyForm.DoSomething(list: TList<TMyObject>;
I recently ran across this problem while trying to implement a service that has
I recently ran across this code in one of the projects I'm working on,
I ran across this code recently which is part of a template class: operator

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.