Search code examples
javascriptteamsite

image size in datacapture.cfg DCT / hp teamsite


I have an browse area in which the user browses and enters an image.

I need to know the height and width of the image to limit it.

var img= IWDatacapture.getItem("banners/mobile-banner/mobile-content[1]/main-image");
var params = new Object();

if(img.length==undefined)
{
    var savnm = IWDatacapture.getWorkarea() + img.getValue();
    params.savnm = savnm;               
    var server = window.location.hostname;
    IWDatacapture.callServer("http://"+server+"/iw-bin/iw_cgi_wrapper.cgi/getFileSize.ipl", params,true);
}

After I make a server call, I didn't understand how to access the image's attributes.


Solution

  • Try something like:

    // Get the full image URL:
    
    var img = IWDatacapture.getItem("banners/mobile-banner/mobile-content[1]/main-image");
    
    // Note: I'm not sure if the following will generate the correct URL, but it should be close. Double check the "workarea" part.
    
    var fullImagePath = "/iw/cci/meta/no-injection/iw-mount/" + IWDatacapture.getWorkarea() + img.getValue();
    
    // Then load the image in the browser to get the dimensions:
    
    var image = new Image();
    
    image.onload = function(){
      var height = image.height;
      var width = image.width;
    
      // Whatever you want to do
    
    }
    
    image.src = fullImagePath;