r90511 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90510‎ | r90511 | r90512 >
Date:05:03, 21 June 2011
Author:neilk
Status:ok
Tags:
Comment:
use orientation in canvas preview. do not blank metadata again when uploaded
Modified paths:
  • /trunk/extensions/UploadWizard/resources/mw.UploadWizard.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UploadWizard/resources/mw.UploadWizard.js
@@ -297,9 +297,8 @@
298298 } catch ( e ) {
299299 meta = null;
300300 }
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+
304303 var dataUrlReader = new FileReader();
305304 dataUrlReader.onload = function() {
306305 image.src = dataUrlReader.result;
@@ -324,6 +323,30 @@
325324
326325
327326 /**
 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+ /**
328351 * Accept the result from a successful API upload transport, and fill our own info
329352 *
330353 * @param result The JSON object from a successful API upload result.
@@ -345,6 +368,7 @@
346369 /**
347370 * Extract image info into our upload object
348371 * Image info is obtained from various different API methods
 372+ * This may overwrite metadata obtained from FileReader.
349373 * @param imageinfo JSON object obtained from API result.
350374 */
351375 extractImageInfo: function( imageinfo ) {
@@ -352,7 +376,9 @@
353377 for ( var key in imageinfo ) {
354378 // we get metadata as list of key-val pairs; convert to object for easier lookup. Assuming that EXIF fields are unique.
355379 if ( key == 'metadata' ) {
356 - _this.imageinfo.metadata = {};
 380+ if ( !mw.isDefined( _this.imageinfo.metadata ) ) {
 381+ _this.imageinfo.metadata = {};
 382+ }
357383 if ( imageinfo.metadata && imageinfo.metadata.length ) {
358384 $j.each( imageinfo.metadata, function( i, pair ) {
359385 if ( pair !== undefined ) {
@@ -595,27 +621,26 @@
596622 },
597623
598624 /**
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
603628 */
604 - getOrientation: function() {
 629+ getOrientationDegrees: function() {
605630 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 ) {
609633 case 8:
610 - orientation = 90;
 634+ orientation = 90; // 'top left' -> 'left bottom'
611635 break;
612636 case 3:
613 - orientation = 180;
 637+ orientation = 180; // 'top left' -> 'bottom right'
614638 break;
615639 case 6:
616 - orientation = 270;
 640+ orientation = 270; // 'top left' -> 'right top'
617641 break;
 642+ case 1:
618643 default:
619 - orientation = 0;
 644+ orientation = 0; // 'top left' -> 'top left'
620645 break;
621646
622647 }
@@ -656,8 +681,8 @@
657682 // if this wiki can rotate images to match their EXIF metadata,
658683 // we should do the same in our preview
659684 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;
662687 }
663688
664689 // swap scaling constraints if needed by rotation...

Follow-up revisions

RevisionCommit summaryAuthorDate
r90568merged changes in UploadWizard from r87529 to r90511. Also modified location ...neilk01:00, 22 June 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r89918Use FileAPI for previews when possible....neilk05:28, 12 June 2011

Status & tagging log