Skip to content

High-quality scale function for canvas and image element. If scale factor < 1, then algorithm for downscale (area average) is used, other than that, bicubic algorithm is used.

License

sapics/scale.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

scale.js

High-quality scale function for canvas and image element. If scale factor < 1, then algorithm for downscale is used, other than that, bicubic algorithm is used.

How to use

Please use dist/scale.min.js, because src/scale.js dose not work.

<html><body>
  <canvas id="inputCanvas"></canvas>
  <img id="inputImage" src="..." />
  <canvas id="exportCanvas"></canvas>
  
  <script src="dist/scale.min.js" />
  <script>
  (function(){
    var inputCanvas = document.getElementById("inputCanvas");
    var inputImage = document.getElementById("inputImage");

    var newCanvas1 = scale(0.7,
                           inputCanvas);
    var newCanvas2 = scale({scaleX:1.7, scaleY:1.4},
                           inputImage,
                           document.getElementById("exportCanvas2"));
    var jpegImage  = scale({width:100, height:200},
                           inputCanvas,
                           'jpeg');
    var pngSrc     = scale(0.7,
                           inputCanvas,
                           'png-src');
  })();
  </script>
</body></html>

Licence

MIT Licence

About

High-quality scale function for canvas and image element. If scale factor < 1, then algorithm for downscale (area average) is used, other than that, bicubic algorithm is used.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published