php den umudu kesince çareyi javascriptte aramaya başladım alert olarak yazdırabiliyorum fakat <img taginin içerisinde kullanamıyorum

var mı yapabilecek bir babayiğit?

<script>
function getMeta(url, callback) {
const img = new Image();
img.src = url;
img.onload = function() { callback(this.width, this.height); }
}
getMeta(
"<?php echo $resim; ?>",
(width, height) => { alert(width + 'px ' + height + 'px') }
);
</script>