LoginSignup
8
7

More than 5 years have passed since last update.

フォームにアップロードされた画像の縦横の長さをサクッと取得する

Posted at

アップロードされたファイルからimgのDomを作って取得

以下はcoffeescriptによるコード

if file = document.getElementById('フォームのID').files[0]
  img        = new Image()
  img.onload = -> alert "#{@width} #{@height}"
  img.src    = (window.URL || window.webkitURL).createObjectURL file

をjsにコンパイルしたもの

var file, img;

if (file = document.getElementById('フォームのID').files[0]) {
  img = new Image();
  img.onload = function() {
    return alert(this.width + " " + this.height);
  };
  img.src = (window.URL || window.webkitURL).createObjectURL(file);
}

いいね!

8
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
7