사용자 도구

사이트 도구


algorithms:이미지썸네일crop크기계산

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
algorithms:이미지썸네일crop크기계산 [2010/12/08 17:36]
kwon37xi
algorithms:이미지썸네일crop크기계산 [2010/12/09 11:22] (현재)
kwon37xi
줄 1: 줄 1:
-====== Image Thumbnail 생성시 Thumbnail 크기에 딱 맞게 crop 하기 ======+====== Image Thumbnail 생성시 Thumbnail 비율에 맞게 crop 하기 ======
 이미지 파일의 썸네일을 만들 때 강제로 썸네일의 지정 크기에 맞게 크기를 고정하거나, 혹은 [[algorithms:이미지축소비율유지|썸네일 지정 크기를 넘지 않으면서 도 원본 이미지의 비율을 유지]]하도록 하는 방법 외에, 썸네일 지정 크기로 만들고, 원본 이미지를 썸네일의 비율에 맞는 영역만 crop 하는 방식을 취할 수 있다. 이미지 파일의 썸네일을 만들 때 강제로 썸네일의 지정 크기에 맞게 크기를 고정하거나, 혹은 [[algorithms:이미지축소비율유지|썸네일 지정 크기를 넘지 않으면서 도 원본 이미지의 비율을 유지]]하도록 하는 방법 외에, 썸네일 지정 크기로 만들고, 원본 이미지를 썸네일의 비율에 맞는 영역만 crop 하는 방식을 취할 수 있다.
  
-C#으로 만들어진 썸네일의 너비/높이 비율에 맞춰 원본 이미지 crop 하는 영역 구하는 방법을 http://www.davidmoore.info/2009/02/07/creating-thumbnail-images-with-automatic-cropping-and-maintaining-aspect-ratio/ 에서 볼 수 있다.+C#으로 만들어진 썸네일의 가로/세로 비율에 맞춰 원본 이미지 crop 하는 영역 구하는 방법을 http://www.davidmoore.info/2009/02/07/creating-thumbnail-images-with-automatic-cropping-and-maintaining-aspect-ratio/ 에서 볼 수 있다.
  
-이의 의사 코드(pseudo code)는 다음과 같다.+이의 Java Code 는 다음과 같다. 
 +<code java>
  
 +public Dimension calculateCropSize(Dimension originalSize,
 +                Dimension thumbnailSize) {
 +        double originalAspectRatio = originalSize.getWidth()
 +                        / originalSize.getHeight();
 +        double thumbnailAspectRatio = thumbnailSize.getWidth()
 +                        / thumbnailSize.getHeight();
 +
 +        if (originalAspectRatio == thumbnailAspectRatio) {
 +                return new Dimension(originalSize);
 +        }
 +
 +        int targetWidth = originalSize.width;
 +        int targetHeight = originalSize.height;
 +
 +        if (thumbnailAspectRatio > originalAspectRatio) {
 +                targetHeight = (int) (originalSize.getWidth() * (thumbnailSize
 +                                .getHeight() / thumbnailSize.getWidth()));
 +        } else {
 +                targetWidth = (int) (originalSize.getHeight() * thumbnailAspectRatio);
 +        }
 +
 +        return new Dimension(targetWidth, targetHeight);
 +}
 +</code>
algorithms/이미지썸네일crop크기계산.1291797408.txt.gz · 마지막으로 수정됨: 2010/12/08 17:36 저자 kwon37xi