Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Scale in Image Report Item
BregoXX
I have an Image Container, with maximum acceptable size of 250x250 px. If a smaller image is added, this image must be displayed as is, without enlargement. I a larger image is added, it has to be downsized to 250 px in proportion. How can I do this?
Find more posts tagged with
Comments
kclark
In the onPrepare() of the image container you could do something like this<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
// 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
}
</pre>
<br />
The script first gets the height and width from the image. This is a string and returns in inches. Then I used the replace to remove the in from height and width. Then I used parseInt() to convert the string to int's so I could compare them. Before I change the image I convert the inches to pixels. Since 1 inch is about 96 pixels I can just do yheight = yheigh * oneInch.<br />
<br />
Then I can change the height and width of the image if it's greater than 250 pixels. Otherwise I leave it alone.
BregoXX
thanks for the reply