smooth-shrink.js

A Javascript library to shrink an image using bilinear interpolation method to make the shrunk image look smoother.

Installation

  • 1. Download the source code from here.
  • 2. Put the code snippet in the HTML file(s) that contain images to be shrunk:
    <script src="js/smooth-shrink.js"></script>
  • 3. Make sure the source image is located in the same server as that of the web page.
  • 4. Create a new SmoothShrink object, initialize, then shrink it.
    var shrinker = new SmoothShrink();
    shrinker.init("...image source URL...");
    shrinker.shrink(width, height); // shrink with your own dimensions
    shrinker.shrinkByScale(width); // OR shrink proportionally based on the width specified
  • 5. Retrieve the URL of the shrunk image with:
    var shrunkImageURL = shrinker.getShrunkImageURL();

Demostration

Try upload your own image and specify dimension(s) after resizing.
Source Image:

Width:
Height:

Original Image

Shrunk Image