用 FileAPI 檢查圖片長寬

imageDimension = 685
checkFileSizeAndUpload = (data) ->
  uploadable = no
  file = data.files[0]
  fileReader = new FileReader
  fileReader.onload = ->
    image = new Image

    image.onload = ->
      if image.width >= imageDimension and image.height >= imageDimension
        data.submit()
        alertify.success "檔案上傳中,請稍後"
      else
        alertify.alert "噢!這張圖太小了。請選擇圖片尺寸至少 #{imageDimension}x#{imageDimension} 像素上傳。"

    image.src = fileReader.result

  fileReader.readAsDataURL(file)

Comments

comments powered by Disqus