Check image width and height on upload with Javascript

http://stackoverflow.com/questions/8903854/check-image-width-and-height-on-upload-with-javascript

by kazu69

HTML

<input type="file" id="file" />

CoffeeScript

_URL = window.URL or window.webkitURL
$('#file').change (event) ->
  file = undefined
  img = undefined
  if file = @files[0]
    img = new Image()
    img.onload = ->
      alert "width:#{@width}, height:#{@height}"

    img.onerror = ->
      alert "not a valid file: #{file.type}"

    img.src = _URL.createObjectURL(file)