Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f1abe48

Browse files
committed
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.
1 parent 0868bb5 commit f1abe48

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

load-image.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* JavaScript Load Image 1.3
2+
* JavaScript Load Image 1.3.1
33
* https://github.com/blueimp/JavaScript-Load-Image
44
*
55
* Copyright 2011, Sebastian Tschan
@@ -169,16 +169,16 @@
169169
(options.minHeight || height) / height
170170
);
171171
if (scale > 1) {
172-
width = (width * scale) << 0;
173-
height = (height * scale) << 0;
172+
width = Math.ceil(width * scale);
173+
height = Math.ceil(height * scale);
174174
}
175175
scale = Math.min(
176176
(options.maxWidth || width) / width,
177177
(options.maxHeight || height) / height
178178
);
179179
if (scale < 1) {
180-
width = (width * scale) << 0;
181-
height = (height * scale) << 0;
180+
width = Math.ceil(width * scale);
181+
height = Math.ceil(height * scale);
182182
}
183183
if (img.getContext || (options.canvas && canvas.getContext)) {
184184
canvas.width = width;

load-image.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "blueimp-load-image",
3-
"version": "1.3.0",
3+
"version": "1.3.1",
44
"title": "JavaScript Load Image",
55
"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.",
66
"keywords": [

0 commit comments

Comments
 (0)