Find your content:

Search form

You are here

Getting the width and height of an image attachment


Is it possible to get the width and height of an image in an Attachment?

I'm looking for a way to make it show properly based on the image.

<apex:image value="{!a.Id}" width="XXX" height="XXX"/>

Attribution to: Joey Chan

Possible Suggestion/Solution #1

I just tried following code and its alerting the width and height correctly. One approach would be to load images like this and add them to the dom as required


  <script type="text/javascript">
    var img = new Image();
    img.onload = function() {
      // you can append this img tag in desired DOM location now with height/width as required.
      alert(this.width + 'x' + this.height);
    img.src = '';


Another approach might be to do like this


<script src="//"></script>
<apex:image id="testImg" value="/s.gif" />
  <script type="text/javascript">
    $(document).ready(function () {
            .attr('src', '')
            // do what you want with height width here
                alert($(this).height() + ' X ' + $(this).width());


Hope this helps

Attribution to: Abhinav Gupta
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content