Home Analytics DevShare
The community of Analytics developers are invited to follow and participate in the developer network.
OpenText technical experts collaborate with supported customers and partners in the Magellan product area.

Resize image

kclarkkclark BIRT GuruEM
edited October 24, 2013 in DevShare
If you need to resize an image that is greater than x pixels. You can put this example in the onPrepare() of your image.
// Approx. how many pixels in one inch
var oneInch = 96; 
// Get the height in inches, returns as a string
var width  = this.width;
var height = this.height;
// Remove "in" from the string
var xwidth  = width.replace("in","");
var xheight = height.replace("in", "");

// Covert the string to int using parseInt()
var yheight = parseInt(xheight);
var ywidth  = parseInt(xwidth);

// Convert inches to pixels.  1 inch ~= 96 pixels   
yheight = yheight * oneInch;   
ywidth  = ywidth  * oneInch;

// If the image height > 250 pixels we can change our max height here
if(yheight > 250) {
  this.height = "250px";
} else {
  // Do nothing

// If the image width > 250 pixels we can change our max width here
if(ywidth > 250) {
  this.width = "250px";
} else {
  // Do nothing
<br />
The script will grab the height and width of an image in inches. Remove "in" and then convert the number into pixels.<br />
After we know how many pixels the image is you can check to see if it is greater than the size you want to allow. If it is then you can resize the image. Otherwise the image is left alone to stay the same size.

Kristopher Clark

Actuate Corporation – The BIRT Company™

http://www.actuate.com | http://birtondemand.com


My Blog



Sign In or Register to comment.