Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

384
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda