Home
Analytics
Question about image-size/image-position
iparker
Hello,
I have the task to handle different images in a report. The path and the file-name are stored in a database-table.
I have the following two problems with the output of the report:
1.) I want to resize the images. Unfortunately the images have different ratios – some images are endwise horizontal (x > y) and some not. Is the a possibility to check the size and the size-ratio of the image by script and set the size of an image to a fix x or y size?
2.) I want to output two images side by side if they are endwise horizontal. If they are not endwise horizontal they don’t fit on the page. How can I output images like this:
image_01 image_02
image_03
image_04 image_05
Is this also a table???
Thanks for some answers!
Best regards,
Timo
Find more posts tagged with
Comments
iparker
I try to set the image-size by a onCreate-Script and it nearly seems too work. But unfortunately I have a problem with work with the dimension-value of an image.
A little example:
In the script I get the height of the image by
height = this.getHeight();
This is a dimension-value like 250px.
But how get I get the simple absolute value 250 without the dimension-information? I read in the documentation something about a getAbsoluteValue()-Method, but all my tries failed.
Thanks for some answers!
Timo
iparker
After a new problem – the birt-api probably doesn’t know the “real” size of the image because birt just knows the “birt-parameters” of the image – I tried to write a function which uses java to get the image-size. The result is the following function:
function setImageSize(file_name)
{
importPackage(Packages.java.io);
importPackage(Packages.java.lang);
importPackage(Packages.java.awt);
importPackage(Packages.java.net);
importPackage(Packages.javax.imageio);
// Datei wird eingelesen
file = new File( params["image_base_path"].value + file_name);
image = ImageIO.read(file);
// Reelle Größen des Bildes werden ermittelt
width = image.getWidth();
height = image.getHeight();
// Aktuelles Größenverhältniss
ratio = width / height;
// Neue Höhe des Bildes wird berechnet und in die internen Variablen
// geschrieben
if(width > height)
{
vars["img_height"] = vars["soll_querformat_hoehe"];
}
else
{
vars["img_height"] = vars["soll_hochkant_hoehe"];
}
// Breite wird in Abhängigkeit zur Höhe berechnet
vars["img_width"] = (ratio * vars["img_height"]);
}
I call the function for each image in the expression-builder with
setImageSize(row["name"]);
Additional I have to set the size of the image in the onCreate-Script-Part of each image with:
this.height = vars["img_height"]+'px';
this.width = vars["img_width"]+'px';