-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path7.3 java
More file actions
32 lines (23 loc) · 937 Bytes
/
7.3 java
File metadata and controls
32 lines (23 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
public class ImageResizer {
static FileFilter filter = new FileFilter() {
public boolean accept(File f)
{
return f.getName().endsWith("png") || f.getName().endsWith("jpg");
}
};
public static void resize(String path, int width) {
File fileImage = new File(path);
File[] files = fileImage.listFiles(filter);
if (!fileImage.exists() || files.length==0) throw new IllegalArgumentException();
for (File file : files) {
try {
BufferedImage image = ImageIO.read(file);
image = Scalr.resize(image,Scalr.Mode.FIT_TO_WIDTH,width);
if (file.getName().endsWith("jpg"))ImageIO.write(image,"jpg",file);
else if (file.getName().endsWith("png")) ImageIO.write(image,"png",file);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}