Resize image

kclark
kclark E
edited February 11, 2022 in Analytics #1
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.
Warning No formatter is installed for the format ipb