How to get Width and Height of image in perspective

Hi,
I am using file upload component to upload the image in perspective, But I want to upload image in 16:9 format.
To calculate aspect ratio I need width and height of uploaded image.
How can I achieve this in perspective?
Thanks.

You can't determine the aspect ratio until the image is uploaded. If it's in a common format (PNG, GIF, JPG) then you can borrow from the technique from this post:

Specifically, the Toolkit.getDefaultToolkit().getImage() - once loaded through that mechanism, you can get the width and height of an image, and from there determine the aspect ratio.

I have tried this but it is throwing an error. i.e. “No module named gateway”.
for this line ‘from com.inductiveautomation.ignition.designer.gateway import DTGatewayInterface’

You don’t need everything else in the example. Only the Toolkit import and related line.

So, In that case ,'object has no attribute ‘openFile’ this error occures.

system.file.openFile() is a gui operation for selecting a file path. For Vision only.

In the file upload component, save your uploaded file to a temporary directory:
https://docs.inductiveautomation.com/display/DOC80/Perspective+-+File+Upload
https://docs.inductiveautomation.com/display/DOC80/system.file.getTempFile

Then parse it with Toolkit.

I am trying this way but getting this error.
type object ‘java.awt.Toolkit’ has no attribute 'defaultToolkit
How can I correct this?

I believe it should be:

javaImage = Toolkit.getDefaultToolkit().getImage(imagePath)

Instead of just defaultToolkit

By using this I am getting image Height and Width but if I resize any image from paint or any other tool and try to upload then this is giving -1 height and width.
Why it is giving -1 , any idea?

Java Documentation says that Image.getWidth() returns -1 when the width is not yet known. Similar behavior is documented for Image.getHeight().

This would suggest that you are trying to retrieve the height and width before the image has been completely loaded.

I would suggest that you use Image.getScaledInstance() to generate a new scaled image with your desired aspect ratio.

How can use Image.getScaledInstance()?