Skip to content

Commit d9fc9ac

Browse files
committed
Do not scale to max/min settings without min/max settings.
1 parent ccb467f commit d9fc9ac

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

load-image.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* JavaScript Load Image 1.1.1
2+
* JavaScript Load Image 1.1.2
33
* https://github.com/blueimp/JavaScript-Load-Image
44
*
55
* Copyright 2011, Sebastian Tschan
@@ -57,14 +57,18 @@
5757
(options.minWidth || img.width) / img.width,
5858
(options.minHeight || img.height) / img.height
5959
);
60-
img.width = parseInt(img.width * scale, 10);
61-
img.height = parseInt(img.height * scale, 10);
60+
if (scale > 1) {
61+
img.width = parseInt(img.width * scale, 10);
62+
img.height = parseInt(img.height * scale, 10);
63+
}
6264
scale = Math.min(
6365
(options.maxWidth || img.width) / img.width,
6466
(options.maxHeight || img.height) / img.height
6567
);
66-
img.width = parseInt(img.width * scale, 10);
67-
img.height = parseInt(img.height * scale, 10);
68+
if (scale < 1) {
69+
img.width = parseInt(img.width * scale, 10);
70+
img.height = parseInt(img.height * scale, 10);
71+
}
6872
if (!options.canvas || !canvas.getContext) {
6973
return img;
7074
}

load-image.min.js

Lines changed: 2 additions & 2 deletions
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
@@ -12,5 +12,5 @@
1212
},
1313
"bugs": "https://github.com/blueimp/JavaScript-Load-Image/issues",
1414
"main": "load-image",
15-
"version": "1.1.1"
15+
"version": "1.1.2"
1616
}

test/test.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* JavaScript Load Image Test 1.1.1
2+
* JavaScript Load Image Test 1.1.2
33
* https://github.com/blueimp/JavaScript-Load-Image
44
*
55
* Copyright 2011, Sebastian Tschan
@@ -120,6 +120,22 @@
120120
}, {minHeight: 180, maxWidth: 160}));
121121
});
122122

123+
$.asyncTest('Do not scale to max settings without min settings', function () {
124+
$.ok($.loadImage(blob, function (img) {
125+
$.start();
126+
$.strictEqual(img.width, 80);
127+
$.strictEqual(img.height, 60);
128+
}, {maxWidth: 160, maxHeight: 120}));
129+
});
130+
131+
$.asyncTest('Do not scale to min settings without max settings', function () {
132+
$.ok($.loadImage(blob, function (img) {
133+
$.start();
134+
$.strictEqual(img.width, 80);
135+
$.strictEqual(img.height, 60);
136+
}, {minWidth: 40, minHeight: 30}));
137+
});
138+
123139
$.module('Canvas');
124140

125141
$.asyncTest('Return img element to callback if options.canvas is not true', function () {

0 commit comments

Comments
 (0)