From a24086828cc6e8c95953e7068406a4967b47f6a6 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Mon, 28 Apr 2014 23:58:25 -0700 Subject: [PATCH] generate QR thumbnails for .webm --- src/Posting/QR.post.coffee | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/Posting/QR.post.coffee b/src/Posting/QR.post.coffee index 25ae0ff11..9f1d25c7c 100644 --- a/src/Posting/QR.post.coffee +++ b/src/Posting/QR.post.coffee @@ -162,27 +162,32 @@ QR.post = class @nodes.label.hidden = false if QR.spoiler URL.revokeObjectURL @URL @showFileData() if @ is QR.selected - unless /^image/.test file.type + unless /^(image|video)\//.test file.type @nodes.el.style.backgroundImage = null return @setThumbnail() setThumbnail: -> # Create a redimensioned thumbnail. - img = $.el 'img' + isVideo = /^video\//.test @file.type + img = $.el (if isVideo then 'video' else 'img') - img.onload = => + $.on img, (if isVideo then 'loadeddata' else 'load'), => # Generate thumbnails only if they're really big. # Resized pictures through canvases look like ass, # so we generate thumbnails `s` times bigger then expected # to avoid crappy resized quality. s = 90 * 2 * window.devicePixelRatio s *= 3 if @file.type is 'image/gif' # let them animate - {height, width} = img - if height < s or width < s - @URL = fileURL - @nodes.el.style.backgroundImage = "url(#{@URL})" - return + if isVideo + height = img.videoHeight + width = img.videoWidth + else + {height, width} = img + if height < s or width < s + @URL = fileURL + @nodes.el.style.backgroundImage = "url(#{@URL})" + return if height <= width width = s / height * width height = s