……………………
public static void compressImg(String filePath, String ext) throws Exception {
int newWidth = 160;
int newHeight = 160;
File imgFile = new File(filePath);
BufferedImage image = ImageIO.read(imgFile);
int width = image.getWidth();
int height = image.getHeight();
if(Math.abs(width-height)==0){
BufferedImage newImage = new BufferedImage(newWidth, newHeight, image.getType());
Graphics2D g = newImage.createGraphics();
g.drawImage(image, 0, 0, newWidth, newHeight, null);
g.dispose();
ImageIO.write(newImage, ext, new File(filePath));
}
}
……………………