Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

378
Views
How to get image size (height & width) and check image using JavaScript on IE?

Are there any JavaScript or jQuery APIs or methods to get the dimensions of an image on the page?

enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This is the solution:

$("#file").change(function (event) {
    var file = this.files[0];
    if (file) {
        var imagefile = file.type;
        var match = ["image/jpeg", "image/png", "image/jpg", "image/tiff"];
        if (!((imagefile == match[0]) || (imagefile == match[1]) || (imagefile ==
            match[2]))) {
            $('#portal_introduce_file').val("");
            this.files = null;
            alert("有効な画像ファイルを選択してください。\n注:許可される画像タイプは jpeg、png、jpg、tiff、pngのみです。")
            return false;
        } else {
            // 画像の寸法を取得するヘルパー
            img = new Image();
            img.src = URL.createObjectURL(file);
            // 次のハンドラーは、画像が正常に読み込まれた後に起動します
            img.onload = function () {
                debugger
                if (img.width <= 750 && img.height <= 170) {
                    $('#portal_introduce_file').val(file.name);
                }
                else {
                    alert('「' + img.width + 'x' + img.height + '」' + 'サイズが無効です。\n' + '画像: 750x170ビクセルで作成');
                    $('#portal_introduce_file').val("");
                }
            };
            img.onerror = function () {
                alert('画像に問題がありました。')
                $('#portal_introduce_file').val("");
            };
        }
    }
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!