generate QR thumbnails for .webm

This commit is contained in:
ccd0 2014-04-28 23:58:25 -07:00
parent 38dbb55fd3
commit a24086828c

View File

@ -162,27 +162,32 @@ QR.post = class
@nodes.label.hidden = false if QR.spoiler @nodes.label.hidden = false if QR.spoiler
URL.revokeObjectURL @URL URL.revokeObjectURL @URL
@showFileData() if @ is QR.selected @showFileData() if @ is QR.selected
unless /^image/.test file.type unless /^(image|video)\//.test file.type
@nodes.el.style.backgroundImage = null @nodes.el.style.backgroundImage = null
return return
@setThumbnail() @setThumbnail()
setThumbnail: -> setThumbnail: ->
# Create a redimensioned thumbnail. # 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. # Generate thumbnails only if they're really big.
# Resized pictures through canvases look like ass, # Resized pictures through canvases look like ass,
# so we generate thumbnails `s` times bigger then expected # so we generate thumbnails `s` times bigger then expected
# to avoid crappy resized quality. # to avoid crappy resized quality.
s = 90 * 2 * window.devicePixelRatio s = 90 * 2 * window.devicePixelRatio
s *= 3 if @file.type is 'image/gif' # let them animate s *= 3 if @file.type is 'image/gif' # let them animate
{height, width} = img if isVideo
if height < s or width < s height = img.videoHeight
@URL = fileURL width = img.videoWidth
@nodes.el.style.backgroundImage = "url(#{@URL})" else
return {height, width} = img
if height < s or width < s
@URL = fileURL
@nodes.el.style.backgroundImage = "url(#{@URL})"
return
if height <= width if height <= width
width = s / height * width width = s / height * width
height = s height = s