Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #32307 from davidflanagan/bug1212226
Browse files Browse the repository at this point in the history
Bug 1212226 - pass the correct EXIF preview metadata when creating a thumbnail r=aosmond
  • Loading branch information
David Flanagan committed Oct 7, 2015
2 parents e273efa + 9e183e7 commit d9125fb
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions apps/camera/js/controllers/preview-gallery.js
Expand Up @@ -404,22 +404,28 @@ PreviewGalleryController.prototype.onHidden = function() {
};

PreviewGalleryController.prototype.updateThumbnail = function() {
var self = this;
// This is the media item that we want to create a thumbnail for.
var media = this.thumbnailItem = this.items[0] || null;
var blob;

if (media === null) {
this.app.emit('newthumbnail', null);
return;
}

if (media.isVideo) {
// To create a thumbanil, we first need to figure out which image
// blob to use, and what the size and rotation of that image is.
var blob; // The image we'll create the thumbnail from.
var metadata = { // The metadata for that image.
rotation: media.rotation,
mirrored: media.mirrored
};

if (media.isVideo) {
// If it is a video we can create a thumbnail from the poster image
blob = media.poster.blob;
media = media.poster;
metadata.width = media.poster.width;
metadata.height = media.poster.height;
} else {

// If it is a photo we want to use the EXIF preview rather than
// decoding the whole image if we can.
if (media.preview) {
Expand All @@ -435,21 +441,23 @@ PreviewGalleryController.prototype.updateThumbnail = function() {
if (Math.abs(fullRatio - previewRatio) < 0.01) {
blob = media.blob.slice(media.preview.start, media.preview.end,
'image/jpeg');
metadata.width = media.preview.width;
metadata.height = media.preview.height;
}
}

// If a thumbnail couldn't be obtained from the EXIF preview,
// use the full image
if (!blob) {
blob = media.blob;
metadata.width = media.width;
metadata.height = media.height;
}
}

createThumbnailImage(blob, media, this.thumbnailSize, gotThumbnail);

function gotThumbnail(blob) {
self.app.emit('newthumbnail', blob);
}
createThumbnailImage(blob, metadata, this.thumbnailSize, (thumbnail) => {
this.app.emit('newthumbnail', thumbnail);
});
};

});

0 comments on commit d9125fb

Please sign in to comment.