Java를 활용한 이미지 리사이징 프로그램 비교

웹사이트나 앱을 만들다 보면 썸네일, 미리보기, 상세보기 등에 사용되는 다양한 크기의 이미지를 자동 변환해야 할 때가 많다.
오늘은 이미지 변환 도구중 대표적인 몇개의 프로그램 사용방법을 정리했다.

 

 1. ImageMagick

ImageMagick은 가장 유명한 이미지 처리 툴이다.

다양한 포맷과 효과를 지원하며, CLI 또는 API로 이미지 리사이징, 포맷 변환 등이 가능하다.

복잡한 이미지 처리작업이 많을 때 사용하는것을 추천하며 자동차 처리를 할 경우 매우 유용하다.

 

설치 방법

Ubuntu sudo apt install imagemagick
macOS brew install imagemagick
Windows 공식 홈페이지 바로가기

 

사용 예제

public void convertWithImageMagick(String input, String output, int width) throws IOException, InterruptedException {
    String cmd = String.format("convert %s -resize %dx %s", input, width, output);
    Process process = Runtime.getRuntime().exec(cmd);
    process.waitFor();
}
 

2. GraphicsMagick

ImageMagick에서 파생한 가벼운 경량화 버전이다.

처리 속도가 매우 빠르지만 서버 CPU,메모리 사용이 적어 대량 이미지 일괄 변환에 유리하다.

설치 방법

Ubuntu sudo apt install graphicsmagick
macOS brew install graphicsmagick
Windows 공식 사이트 바로 가기
 

사용 예제

public void convertWithGraphicsMagick(String input, String output, int width) throws IOException, InterruptedException {
    String cmd = String.format("gm convert %s -resize %dx %s", input, width, output);
    Process process = Runtime.getRuntime().exec(cmd);
    process.waitFor();
}

 

3. FFmpeg

FFmpeg은 원래 비디오/오디오 변환 툴로 유명하지만, 이미지 리사이징도 지원한다.

영상+이미지 자동화가 함께 필요한 경우 고려해 볼만하고 이미지를 동영상 처럼 일괄 프레임 처리할때도 유용하다.

 

설치 방법

Ubuntu sudo apt install ffmpeg
macOS brew install ffmpeg
Windows 공식 사이트 바로 가기
 

사용 예제

public void convertWithFFmpeg(String input, String output, int width) throws IOException, InterruptedException {
    String cmd = String.format("ffmpeg -i %s -vf scale=%d:-1 %s", input, width, output);
    Process process = Runtime.getRuntime().exec(cmd);
    process.waitFor();
}

4.NConvert

XnView에서 만든 CLI 이미지 처리 도구로, 윈도우에서 주로 사용된다.

특징으로는 설치 없이 윈도우에서 바로 실행이 가능하다.

 

 

설치 방법

사용 예제

public void convertWithNConvert(String input, String output, int width) throws IOException, InterruptedException {
    String cmd = String.format("nconvert -out jpeg -resize %d 0 -o %s %s", width, output, input);
    Process process = Runtime.getRuntime().exec(cmd);
    process.waitFor();
}