Get image width and height

0
We expose images over a REST api. To expose the image is fine, but now the customer also need the width and height of the image. Is there a way to do this or do we need to build our own JA?
asked
2 answers
4

Hello Kim,

Could you try JA following:

        // BEGIN USER CODE
        try {
            if (img == null)
                throw new Exception("Image was be null.");
            
            InputStream is = Core.getFileDocumentContent(getContext(), __img);
            
            BufferedImage bimg = ImageIO.read(is);
            int width          = bimg.getWidth();
            int height         = bimg.getHeight();
            
            ImageDimension imgDimension = new ImageDimension(getContext());
            
            imgDimension.setWidth(width);
            imgDimension.setHeight(height);
            
            return imgDimension.getMendixObject();
        } catch (Exception e) {
            throw new com.mendix.systemwideinterfaces.MendixRuntimeException(e);
        }
        // END USER CODE
 

Note: The "__img" is IMendixObject.

answered