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
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