import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import javax.imageio.ImageIO;
public class CommonUtil {
public CommonUtil(){
}
/**
* 썸네일 만들기
* @param width
* @param height
* @param loadFile
* @param saveFile
* @param zoom
* @throws IOException
*/
public static void createThumbnail(int width, int height, String loadFile, String saveFile, int zoom) throws IOException{
File save = new File(saveFile.replaceAll("/", "\\"+File.separator));
FileInputStream fis = new FileInputStream(loadFile.replaceAll("/", "\\"+File.separator));
BufferedImage im = ImageIO.read(fis);
if (zoom<=0) zoom = 1;
BufferedImage thumb = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = thumb.createGraphics();
g2.drawImage(im, 0, 0, width, height, null);
ImageIO.write(thumb, "jpg", save);
}
/**
* 썸네일 삭제
* @param thumbnail_path
*/
public static void deleteThumbnail(String thumbnail_path){
File file = new File(thumbnail_path);
if(file.exists()){
file.delete();
}
}
public static void main(String args[]){
String loadFile = "http://localhost:8080/2010/07/15/LZHABUhgGy1279183572640.JPG";
String saveFile = "D://dev/test.jpg";
int zoom = 5;
try {
CommonUtil.createThumbnail(124, 144, loadFile, saveFile, zoom);
} catch (IOException e) {
e.printStackTrace();
}
}
}