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

168
Visualizações
Get Image size (not dimension) inside image tag using javascript

I have an <img> tag which is filled with dynamic src attribute. I would like to display the image size (in bytes) upon image load using javascript/jQuery.

I tried using the below. But, it returns zero in all 3 properties.

$('#img').on('load',
                function() {
                    var imgUrl = $(this).attr("src");
                    var imgPerf = performance.getEntriesByName(imgUrl)[0];
                    console.log(Math.round(imgPerf.decodedBodySize)); // returns 0
                    console.log(Math.round(imgPerf.encodedBodySize)); // returns 0
                    console.log(Math.round(imgPerf.transferSize)); // returns 0
                });

Is there any other possible ways to get the image size value?

FYI, the images are loaded from different domain.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

if you have image url you can try this:

const fileImg = await fetch(URL_TO_IMG).then(r => r.blob());

This will get the resource through HTTP and then returns the full binary as a blob object, then you can access its properties including its size in bytes as:

fileImg.size
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