Index: trunk/extensions/UploadWizard/resources/mw.UploadWizard.js |
— | — | @@ -297,9 +297,8 @@ |
298 | 298 | } catch ( e ) { |
299 | 299 | meta = null; |
300 | 300 | } |
301 | | - _this.imageinfo = {}; |
302 | | - _this.imageinfo.metadata = meta; // TODO this is not the same format as API imageinfo; reconcile |
303 | | - |
| 301 | + _this.extractMetadataFromJpegMeta( meta ); |
| 302 | + |
304 | 303 | var dataUrlReader = new FileReader(); |
305 | 304 | dataUrlReader.onload = function() { |
306 | 305 | image.src = dataUrlReader.result; |
— | — | @@ -324,6 +323,30 @@ |
325 | 324 | |
326 | 325 | |
327 | 326 | /** |
| 327 | + * Map fields from jpegmeta's metadata return into our format (which is more like the imageinfo returned from the API |
| 328 | + * @param {Object} (as returned by jpegmeta) |
| 329 | + */ |
| 330 | + extractMetadataFromJpegMeta: function( meta ) { |
| 331 | + if ( !mw.isDefined( this.imageinfo ) ) { |
| 332 | + this.imageinfo = {}; |
| 333 | + } |
| 334 | + if ( !mw.isDefined( this.imageinfo.metadata ) ) { |
| 335 | + this.imageinfo.metadata = {}; |
| 336 | + } |
| 337 | + if ( meta.tiff && meta.tiff.Orientation ) { |
| 338 | + this.imageinfo.metadata.orientation = meta.tiff.Orientation.value; |
| 339 | + } |
| 340 | + if ( meta.general ) { |
| 341 | + if ( meta.general.pixelHeight ) { |
| 342 | + this.imageinfo.height = meta.general.pixelHeight.value; |
| 343 | + } |
| 344 | + if ( meta.general.pixelWidth ) { |
| 345 | + this.imageinfo.width = meta.general.pixelWidth.value; |
| 346 | + } |
| 347 | + } |
| 348 | + }, |
| 349 | + |
| 350 | + /** |
328 | 351 | * Accept the result from a successful API upload transport, and fill our own info |
329 | 352 | * |
330 | 353 | * @param result The JSON object from a successful API upload result. |
— | — | @@ -345,6 +368,7 @@ |
346 | 369 | /** |
347 | 370 | * Extract image info into our upload object |
348 | 371 | * Image info is obtained from various different API methods |
| 372 | + * This may overwrite metadata obtained from FileReader. |
349 | 373 | * @param imageinfo JSON object obtained from API result. |
350 | 374 | */ |
351 | 375 | extractImageInfo: function( imageinfo ) { |
— | — | @@ -352,7 +376,9 @@ |
353 | 377 | for ( var key in imageinfo ) { |
354 | 378 | // we get metadata as list of key-val pairs; convert to object for easier lookup. Assuming that EXIF fields are unique. |
355 | 379 | if ( key == 'metadata' ) { |
356 | | - _this.imageinfo.metadata = {}; |
| 380 | + if ( !mw.isDefined( _this.imageinfo.metadata ) ) { |
| 381 | + _this.imageinfo.metadata = {}; |
| 382 | + } |
357 | 383 | if ( imageinfo.metadata && imageinfo.metadata.length ) { |
358 | 384 | $j.each( imageinfo.metadata, function( i, pair ) { |
359 | 385 | if ( pair !== undefined ) { |
— | — | @@ -595,27 +621,26 @@ |
596 | 622 | }, |
597 | 623 | |
598 | 624 | /** |
599 | | - * Return the orientation of the image. Relies on TIFF metadata that |
600 | | - * may have been extracted at filereader stage, or returns 0. |
601 | | - * @param {Object} metadata as yielded by getMetadata() |
602 | | - * @return {Integer} rotation to be applied: 0, 90, 180 or 270 |
| 625 | + * Return the orientation of the image in degrees. Relies on metadata that |
| 626 | + * may have been extracted at filereader stage, or after the upload when we fetch metadata. Default returns 0. |
| 627 | + * @return {Integer} orientation in degrees: 0, 90, 180 or 270 |
603 | 628 | */ |
604 | | - getOrientation: function() { |
| 629 | + getOrientationDegrees: function() { |
605 | 630 | var orientation = 0; |
606 | | - if ( this.imageinfo && this.imageinfo.metadata && |
607 | | - this.imageinfo.metadata.tiff && this.imageinfo.metadata.tiff.Orientation ) { |
608 | | - switch ( this.imageinfo.metadata.tiff.Orientation.value ) { |
| 631 | + if ( this.imageinfo && this.imageinfo.metadata && this.imageinfo.metadata.orientation ) { |
| 632 | + switch ( this.imageinfo.metadata.orientation ) { |
609 | 633 | case 8: |
610 | | - orientation = 90; |
| 634 | + orientation = 90; // 'top left' -> 'left bottom' |
611 | 635 | break; |
612 | 636 | case 3: |
613 | | - orientation = 180; |
| 637 | + orientation = 180; // 'top left' -> 'bottom right' |
614 | 638 | break; |
615 | 639 | case 6: |
616 | | - orientation = 270; |
| 640 | + orientation = 270; // 'top left' -> 'right top' |
617 | 641 | break; |
| 642 | + case 1: |
618 | 643 | default: |
619 | | - orientation = 0; |
| 644 | + orientation = 0; // 'top left' -> 'top left' |
620 | 645 | break; |
621 | 646 | |
622 | 647 | } |
— | — | @@ -656,8 +681,8 @@ |
657 | 682 | // if this wiki can rotate images to match their EXIF metadata, |
658 | 683 | // we should do the same in our preview |
659 | 684 | if ( mw.config.get( 'wgFileCanRotate' ) ) { |
660 | | - var orientation = this.getOrientation(); |
661 | | - rotation = orientation ? 360 - orientation : 0; |
| 685 | + var angle = this.getOrientationDegrees(); |
| 686 | + rotation = angle ? 360 - angle : 0; |
662 | 687 | } |
663 | 688 | |
664 | 689 | // swap scaling constraints if needed by rotation... |