Skip to content

Commit f551c8c

Browse files
committed
Merge pull request mailru#248 from galanin/width-height
+ resize strategies: 'width', 'height' (v2.0.8)
2 parents 1e726b8 + 97ece17 commit f551c8c

File tree

10 files changed

+85
-18
lines changed

10 files changed

+85
-18
lines changed

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ Resize image.
773773

774774
* width — new image width
775775
* height — new image height
776-
* strategy — enum: `min`, `max`, `preview`. By default `undefined`.
776+
* strategy — enum: `min`, `max`, `preview`, `width`, `height`. By default `undefined`.
777777

778778
```js
779779
FileAPI.Image(imageFile)
@@ -790,6 +790,14 @@ FileAPI.Image(imageFile)
790790

791791
})
792792
;
793+
794+
// Resize image on by fixed height.
795+
FileAPI.Image(imageFile)
796+
.resize(240, 'height')
797+
.get(function (err/**String*/, img/**HTMLElement*/){
798+
799+
})
800+
;
793801
```
794802

795803
---
@@ -1388,6 +1396,11 @@ Button like link.
13881396
## Changelog
13891397
13901398
1399+
### 2.0.8
1400+
<ul>
1401+
<li>Two new resize strategies `width` and `height`</li>
1402+
</ul>
1403+
13911404
### 2.0.7
13921405
<ul>
13931406
<li>#214: iframe transport under IE8</li>

README.ru.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ FileAPI.Image(imageFile)
752752

753753
* width — новая ширина
754754
* height — новая высота
755-
* strategy — enum: `min`, `max`, `preview`. По умолчанию `undefined`.
755+
* strategy — enum: `min`, `max`, `preview`, `width`, `height`. По умолчанию `undefined`.
756756

757757
```js
758758
FileAPI.Image(imageFile)
@@ -769,6 +769,14 @@ FileAPI.Image(imageFile)
769769

770770
})
771771
;
772+
773+
// По заданной высоте.
774+
FileAPI.Image(imageFile)
775+
.resize(240, 'height')
776+
.get(function (err/**String*/, img/**HTMLElement*/){
777+
778+
})
779+
;
772780
```
773781

774782
---

dist/FileAPI.html5.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! FileAPI 2.0.7 - BSD | git://github.com/mailru/FileAPI.git
1+
/*! FileAPI 2.0.8 - BSD | git://github.com/mailru/FileAPI.git
22
* FileAPI — a set of javascript tools for working with files. Multiupload, drag'n'drop and chunked file upload. Images: crop, resize and auto orientation by EXIF.
33
*/
44

@@ -278,7 +278,7 @@
278278
* FileAPI (core object)
279279
*/
280280
api = {
281-
version: '2.0.7',
281+
version: '2.0.8',
282282

283283
cors: false,
284284
html5: true,
@@ -1864,7 +1864,7 @@
18641864
},
18651865

18661866
resize: function (w, h, strategy){
1867-
if( /min|max/.test(h) ){
1867+
if( /min|max|height|width/.test(h) ){
18681868
strategy = h;
18691869
h = w;
18701870
}
@@ -2047,6 +2047,12 @@
20472047
}
20482048
}
20492049
}
2050+
else if( strategy == 'height' ){
2051+
dw = dh * sf;
2052+
}
2053+
else if( strategy == 'width' ){
2054+
dh = dw / sf;
2055+
}
20502056
else if( strategy ){
20512057
if( !(sw > dw || sh > dh) ){
20522058
dw = sw;

dist/FileAPI.html5.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.

dist/FileAPI.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! FileAPI 2.0.7 - BSD | git://github.com/mailru/FileAPI.git
1+
/*! FileAPI 2.0.8 - BSD | git://github.com/mailru/FileAPI.git
22
* FileAPI — a set of javascript tools for working with files. Multiupload, drag'n'drop and chunked file upload. Images: crop, resize and auto orientation by EXIF.
33
*/
44

@@ -278,7 +278,7 @@
278278
* FileAPI (core object)
279279
*/
280280
api = {
281-
version: '2.0.7',
281+
version: '2.0.8',
282282

283283
cors: false,
284284
html5: true,
@@ -1864,7 +1864,7 @@
18641864
},
18651865

18661866
resize: function (w, h, strategy){
1867-
if( /min|max/.test(h) ){
1867+
if( /min|max|height|width/.test(h) ){
18681868
strategy = h;
18691869
h = w;
18701870
}
@@ -2047,6 +2047,12 @@
20472047
}
20482048
}
20492049
}
2050+
else if( strategy == 'height' ){
2051+
dw = dh * sf;
2052+
}
2053+
else if( strategy == 'width' ){
2054+
dh = dw / sf;
2055+
}
20502056
else if( strategy ){
20512057
if( !(sw > dw || sh > dh) ){
20522058
dw = sw;
@@ -3491,8 +3497,8 @@
34913497
_css(dummy, {
34923498
top: 0
34933499
, left: 0
3494-
, width: target.offsetWidth + 100
3495-
, height: target.offsetHeight + 100
3500+
, width: target.offsetWidth
3501+
, height: target.offsetHeight
34963502
, zIndex: 1e6+'' // set max zIndex
34973503
, position: 'absolute'
34983504
});

dist/FileAPI.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/FileAPI.Image.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
},
7474

7575
resize: function (w, h, strategy){
76-
if( /min|max/.test(h) ){
76+
if( /min|max|height|width/.test(h) ){
7777
strategy = h;
7878
h = w;
7979
}
@@ -256,6 +256,12 @@
256256
}
257257
}
258258
}
259+
else if( strategy == 'height' ){
260+
dw = dh * sf;
261+
}
262+
else if( strategy == 'width' ){
263+
dh = dw / sf;
264+
}
259265
else if( strategy ){
260266
if( !(sw > dw || sh > dh) ){
261267
dw = sw;

lib/FileAPI.core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184
* FileAPI (core object)
185185
*/
186186
api = {
187-
version: '2.0.7',
187+
version: '2.0.8',
188188

189189
cors: false,
190190
html5: true,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "fileapi",
33
"exportName": "FileAPI",
4-
"version": "2.0.7",
4+
"version": "2.0.8",
55
"devDependencies": {
66
"grunt": "~0.4.5",
77
"grunt-version": "~0.3.0",

tests/tests.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,34 @@ module('FileAPI');
521521
}
522522
});
523523

524+
// strategy: 'height'
525+
queue.inc();
526+
FileAPI.upload({
527+
url: 'http://rubaxa.org/FileAPI/server/ctrl.php',
528+
files: { image: file },
529+
imageTransform: { width: 100, height: 100, strategy: 'height' },
530+
complete: function (err, res){
531+
queue.next();
532+
var res = FileAPI.parseJSON(res.responseText);
533+
equal(res.images['image'].width, 141, 'height.width');
534+
equal(res.images['image'].height, 100, 'height.height');
535+
}
536+
});
537+
538+
// strategy: 'width'
539+
queue.inc();
540+
FileAPI.upload({
541+
url: 'http://rubaxa.org/FileAPI/server/ctrl.php',
542+
files: { image: file },
543+
imageTransform: { width: 100, height: 100, strategy: 'width' },
544+
complete: function (err, res){
545+
queue.next();
546+
var res = FileAPI.parseJSON(res.responseText);
547+
equal(res.images['image'].width, 100, 'width.width');
548+
equal(res.images['image'].height, 70, 'width.height');
549+
}
550+
});
551+
524552
// preview
525553
queue.inc();
526554
FileAPI.upload({

0 commit comments

Comments
 (0)