Permalink
Browse files

Use Math.ceil instead of bitwise left shift.

Width or height might exceed 2147483648 pixels, which results in
negative numbers when using bitwise shift.
Also, 1px scaled with a factor of less than 1 should still be 1px.
  • Loading branch information...
1 parent 0868bb5 commit f1abe48c7aa3880da31928736afcb454aaeb76d6 @blueimp committed Mar 18, 2013
Showing with 7 additions and 7 deletions.
  1. +5 −5 load-image.js
  2. +1 −1 load-image.min.js
  3. +1 −1 package.json
View
@@ -1,5 +1,5 @@
/*
- * JavaScript Load Image 1.3
+ * JavaScript Load Image 1.3.1
* https://github.com/blueimp/JavaScript-Load-Image
*
* Copyright 2011, Sebastian Tschan
@@ -169,16 +169,16 @@
(options.minHeight || height) / height
);
if (scale > 1) {
- width = (width * scale) << 0;
- height = (height * scale) << 0;
+ width = Math.ceil(width * scale);
+ height = Math.ceil(height * scale);
}
scale = Math.min(
(options.maxWidth || width) / width,
(options.maxHeight || height) / height
);
if (scale < 1) {
- width = (width * scale) << 0;
- height = (height * scale) << 0;
+ width = Math.ceil(width * scale);
+ height = Math.ceil(height * scale);
}
if (img.getContext || (options.canvas && canvas.getContext)) {
canvas.width = width;
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -1,6 +1,6 @@
{
"name": "blueimp-load-image",
- "version": "1.3.0",
+ "version": "1.3.1",
"title": "JavaScript Load Image",
"description": "JavaScript Load Image is a function to load images provided as File or Blob objects or via URL. It returns an optionally scaled HTML img or canvas element.",
"keywords": [

0 comments on commit f1abe48

Please sign in to comment.