Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

162
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda