Skip to content

Instantly share code, notes, and snippets.

@jeffsaracco
Created February 21, 2014 15:56
Show Gist options
  • Save jeffsaracco/9136849 to your computer and use it in GitHub Desktop.
Save jeffsaracco/9136849 to your computer and use it in GitHub Desktop.
Get image dimensions in coffeescript
onRender: ->
@$('#fileupload').fileupload
dropZone: @$(@itemViewContainer)
headers:
token: App.Entities.Session.getCurrentSession().get("token")
dataType: 'json',
# done: (e, data) =>
# @collection.push(new App.Entities.Image(data.result))
add: (e, data) =>
@getFileSize(data)
getFileSize: (data) ->
$.each(data.files, (index, file) =>
@_getFileSize(file, data)
)
data.submit()
_getFileSize: (file, data) ->
reader = new FileReader()
img = new Image()
reader.onload = (e) =>
img.src = e.target.result
@collection.push(new App.Entities.Image(gallery_path: img.src))
img.onload = ->
console.log("width=" + @width + " height=" + @height)
reader.readAsDataURL file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment