How to check if a deleted image meets certain specifications

I'm doing some coding in JSP / Java (without any frameworks or other weird stuff) and I'm stuck trying to find a way to check if the remote image (by url) conforms to some specs like a specific height and width.

Is there a way to do this in JSP / Java? It's pretty easy in PHP, but I can't find the way here ...

Thank you for your time. Regards.

0


source to share


1 answer


The easiest way, if possible, is to use the ImageIO class to create a BufferedImage, although this is not the only mechanism in the standard library.



public static void main(String[] args) throws IOException {
    URL imageUrl = new URL("http://www.google.com/intl/en_ALL/images/logo.gif");
    BufferedImage image = ImageIO.read(imageUrl);
    System.out.println("Width="+image.getWidth());
    System.out.println("Height="+image.getHeight());
}

      

+4


source







All Articles