Skip to content

Commit e7a952b

Browse files
committed
* imageTransform.type -> imageTransform.strategy
1 parent c763739 commit e7a952b

File tree

9 files changed

+88
-42
lines changed

9 files changed

+88
-42
lines changed

README.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,12 +765,12 @@ FileAPI.Image(imageFile)
765765
---
766766

767767
<a name="FileAPI.Image.resize"></a>
768-
### resize(width`:Number`, height`:Number`[, type`:String`])`:FileAPI.Image`
768+
### resize(width`:Number`, height`:Number`[, strategy`:String`])`:FileAPI.Image`
769769
Resize image.
770770

771771
* width — new image width
772772
* height — new image height
773-
* type — enum: `min`, `max`, `preview`. By default `undefined`.
773+
* strategy — enum: `min`, `max`, `preview`. By default `undefined`.
774774

775775
```js
776776
FileAPI.Image(imageFile)
@@ -1377,6 +1377,25 @@ Button like link.
13771377
13781378
<a name="Changelog"></a>
13791379
## Changelog
1380+
<ul>
1381+
<li>* resize: `imageTransform.type` rename to `imageTransform.strategy` (!!!)</li>
1382+
</ul>
1383+
1384+
### 2.0.2
1385+
<ul>
1386+
<li>+ test: upload headers</li>
1387+
<li>+ test: upload + camanjs</li>
1388+
<li>+ test: upload + autoOrientation</li>
1389+
<li>FileAPI.class.php: + HTTP header Content-Type: application/json</li>
1390+
<li>#143: + `FileAPI.flashWebcamUrl` option</li>
1391+
<li>* merge v1.2.7</li>
1392+
<li>+ `FileAPI.formData: true` option</li>
1393+
</il>
1394+
1395+
### 2.0.1
1396+
<ul>
1397+
<li>+ support 'filter' prop in imageTransform</li>
1398+
</il>
13801399
13811400
### 2.0.0
13821401
<ul>

README.ru.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,12 +747,12 @@ FileAPI.Image(imageFile)
747747
---
748748

749749
<a name="FileAPI.Image.resize"></a>
750-
### resize(width`:Number`, height`:Number`[, type`:String`])`:FileAPI.Image`
750+
### resize(width`:Number`, height`:Number`[, strategy`:String`])`:FileAPI.Image`
751751
Ресайз.
752752

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

757757
```js
758758
FileAPI.Image(imageFile)

dist/FileAPI.html5.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,13 +1832,13 @@
18321832
return this.set({ sx: x, sy: y, sw: w, sh: h || w });
18331833
},
18341834

1835-
resize: function (w, h, type){
1836-
if( typeof h == 'string' ){
1837-
type = h;
1835+
resize: function (w, h, strategy){
1836+
if( /min|max/.test(h) ){
1837+
strategy = h;
18381838
h = w;
18391839
}
18401840

1841-
return this.set({ dw: w, dh: h, resize: type });
1841+
return this.set({ dw: w, dh: h || w, resize: strategy });
18421842
},
18431843

18441844
preview: function (w, h){
@@ -1990,10 +1990,10 @@
19901990
, dw = m.dw = m.dw || sw
19911991
, dh = m.dh = m.dh || sh
19921992
, sf = sw/sh, df = dw/dh
1993-
, type = m.resize
1993+
, strategy = m.resize
19941994
;
19951995

1996-
if( type == 'preview' ){
1996+
if( strategy == 'preview' ){
19971997
if( dw != sw || dh != sh ){
19981998
// Make preview
19991999
var w, h;
@@ -2014,12 +2014,12 @@
20142014
}
20152015
}
20162016
}
2017-
else if( type ){
2017+
else if( strategy ){
20182018
if( !(sw > dw || sh > dh) ){
20192019
dw = sw;
20202020
dh = sh;
20212021
}
2022-
else if( type == 'min' ){
2022+
else if( strategy == 'min' ){
20232023
dw = round(sf < df ? min(sw, dw) : dh*sf);
20242024
dh = round(sf < df ? dw/sf : min(sh, dh));
20252025
}
@@ -2099,7 +2099,7 @@
20992099
params(img, ImgTrans);
21002100
}
21012101
else if( params.width ){
2102-
ImgTrans[params.preview ? 'preview' : 'resize'](params.width, params.height, params.type);
2102+
ImgTrans[params.preview ? 'preview' : 'resize'](params.width, params.height, params.strategy);
21032103
}
21042104
else {
21052105
if( params.maxWidth && (img.width > params.maxWidth || img.height > params.maxHeight) ){

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

dist/FileAPI.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,13 +1832,13 @@
18321832
return this.set({ sx: x, sy: y, sw: w, sh: h || w });
18331833
},
18341834

1835-
resize: function (w, h, type){
1836-
if( typeof h == 'string' ){
1837-
type = h;
1835+
resize: function (w, h, strategy){
1836+
if( /min|max/.test(h) ){
1837+
strategy = h;
18381838
h = w;
18391839
}
18401840

1841-
return this.set({ dw: w, dh: h, resize: type });
1841+
return this.set({ dw: w, dh: h || w, resize: strategy });
18421842
},
18431843

18441844
preview: function (w, h){
@@ -1990,10 +1990,10 @@
19901990
, dw = m.dw = m.dw || sw
19911991
, dh = m.dh = m.dh || sh
19921992
, sf = sw/sh, df = dw/dh
1993-
, type = m.resize
1993+
, strategy = m.resize
19941994
;
19951995

1996-
if( type == 'preview' ){
1996+
if( strategy == 'preview' ){
19971997
if( dw != sw || dh != sh ){
19981998
// Make preview
19991999
var w, h;
@@ -2014,12 +2014,12 @@
20142014
}
20152015
}
20162016
}
2017-
else if( type ){
2017+
else if( strategy ){
20182018
if( !(sw > dw || sh > dh) ){
20192019
dw = sw;
20202020
dh = sh;
20212021
}
2022-
else if( type == 'min' ){
2022+
else if( strategy == 'min' ){
20232023
dw = round(sf < df ? min(sw, dw) : dh*sf);
20242024
dh = round(sf < df ? dw/sf : min(sh, dh));
20252025
}
@@ -2099,7 +2099,7 @@
20992099
params(img, ImgTrans);
21002100
}
21012101
else if( params.width ){
2102-
ImgTrans[params.preview ? 'preview' : 'resize'](params.width, params.height, params.type);
2102+
ImgTrans[params.preview ? 'preview' : 'resize'](params.width, params.height, params.strategy);
21032103
}
21042104
else {
21052105
if( params.maxWidth && (img.width > params.maxWidth || img.height > params.maxHeight) ){

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

lib/FileAPI.Image.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@
6767
return this.set({ sx: x, sy: y, sw: w, sh: h || w });
6868
},
6969

70-
resize: function (w, h, type){
71-
if( typeof h == 'string' ){
72-
type = h;
70+
resize: function (w, h, strategy){
71+
if( /min|max/.test(h) ){
72+
strategy = h;
7373
h = w;
7474
}
7575

76-
return this.set({ dw: w, dh: h, resize: type });
76+
return this.set({ dw: w, dh: h || w, resize: strategy });
7777
},
7878

7979
preview: function (w, h){
@@ -225,10 +225,10 @@
225225
, dw = m.dw = m.dw || sw
226226
, dh = m.dh = m.dh || sh
227227
, sf = sw/sh, df = dw/dh
228-
, type = m.resize
228+
, strategy = m.resize
229229
;
230230

231-
if( type == 'preview' ){
231+
if( strategy == 'preview' ){
232232
if( dw != sw || dh != sh ){
233233
// Make preview
234234
var w, h;
@@ -249,12 +249,12 @@
249249
}
250250
}
251251
}
252-
else if( type ){
252+
else if( strategy ){
253253
if( !(sw > dw || sh > dh) ){
254254
dw = sw;
255255
dh = sh;
256256
}
257-
else if( type == 'min' ){
257+
else if( strategy == 'min' ){
258258
dw = round(sf < df ? min(sw, dw) : dh*sf);
259259
dh = round(sf < df ? dw/sf : min(sh, dh));
260260
}
@@ -334,7 +334,7 @@
334334
params(img, ImgTrans);
335335
}
336336
else if( params.width ){
337-
ImgTrans[params.preview ? 'preview' : 'resize'](params.width, params.height, params.type);
337+
ImgTrans[params.preview ? 'preview' : 'resize'](params.width, params.height, params.strategy);
338338
}
339339
else {
340340
if( params.maxWidth && (img.width > params.maxWidth || img.height > params.maxHeight) ){

statics/docs.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tests/tests.js

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -382,24 +382,51 @@ module('FileAPI');
382382

383383

384384

385-
FileAPI.html5 && test('upload + imageTransform', function (){
385+
FileAPI.html5 && test('upload + imageTransform (min, max, preview)', function (){
386386
var file = FileAPI.getFiles(uploadForm['image.jpg'])[0];
387+
var queue = FileAPI.queue(start);
387388

388389
stop();
390+
391+
// strategy: 'min'
392+
queue.inc();
389393
FileAPI.upload({
390394
url: 'http://rubaxa.org/FileAPI/server/ctrl.php',
391395
files: { image: file },
392-
imageTransform: {
393-
width: 100,
394-
height: 100,
395-
rotate: 'auto',
396-
preview: true
397-
},
396+
imageTransform: { width: 100, height: 100, strategy: 'min' },
397+
complete: function (err, res){
398+
queue.next();
399+
var res = FileAPI.parseJSON(res.responseText);
400+
equal(res.images['image'].width, 141, 'min.width');
401+
equal(res.images['image'].height, 100, 'min.height');
402+
}
403+
});
404+
405+
// strategy: 'max'
406+
queue.inc();
407+
FileAPI.upload({
408+
url: 'http://rubaxa.org/FileAPI/server/ctrl.php',
409+
files: { image: file },
410+
imageTransform: { width: 100, height: 100, strategy: 'max' },
411+
complete: function (err, res){
412+
queue.next();
413+
var res = FileAPI.parseJSON(res.responseText);
414+
equal(res.images['image'].width, 100, 'max.width');
415+
equal(res.images['image'].height, 71, 'max.height');
416+
}
417+
});
418+
419+
// preview
420+
queue.inc();
421+
FileAPI.upload({
422+
url: 'http://rubaxa.org/FileAPI/server/ctrl.php',
423+
files: { image: file },
424+
imageTransform: { width: 100, height: 100, rotate: 'auto', preview: true },
398425
complete: function (err, res){
399426
var res = FileAPI.parseJSON(res.responseText);
400427

401428
imageEqual(res.images.image.dataURL, 'files/samples/'+browser+'-image-auto-100x100.jpeg', 'image auto 100x100.png', function (){
402-
start();
429+
queue.next();
403430
});
404431
}
405432
});

0 commit comments

Comments
 (0)