2011-01-21 47 views
2

分辨率我有一大堆的圖片,具有不同的分辨率。 此外還有風景和肖像照片的混合。我需要將圖像調整爲一個分辨率(1024x768)。如果我有一個人像圖片,最大高度必須是768,我的風景圖片必須有1024調整圖像到一個

即過,必須要由黑色空間中的最大寬度。 現在我正在使用mogrify -resize 1024x768 -verbose *.jpg

我知道我可以使用1024x!768,但就像我說我使用不同種類的圖片。 我的EXIF信息還沒有包含有關,如果圖片是風景或沒有信息。

回答

1

我使用ImageMagick的此類任務。安裝時,你有「轉換」命令,這是很常見的,並且你的任務很容易。

+0

丹尼爾:我也確實看到了這個工具。你有一些建議,我需要使用哪些參數? – Grezly 2011-01-21 19:48:52

0

你將不得不裁剪圖像來獲得相同的縱橫比,那麼你就可以調整圖像以獲得所需的分辨率。使用nodejs(imagemagick命令行工具)的代碼示例:

var width = 166; 
var height = 117; 
var ratio_new = width/height; 
var ratio_old = image_file.width_orig/image_file.height_orig; 
var pixels_too_much = 0; 
var geometry = ''; 

if (ratio_old > ratio_new) 
{ 
    config.debug && console.log ("remove horizontal pixel!"); 
    pixels_too_much = parseInt(image_file.width_orig - (image_file.height_orig * ratio_new))-1; 
    geometry = parseInt(image_file.height_orig * ratio_new + 0.5) + 'x' + image_file.height_orig; 
    geometry += "+" + parseInt(pixels_too_much/2) + "+0\!"; 
} 
else if (ratio_old < ratio_new) 
{ 
    config.debug && console.log ("remove vertikal pixel"); 
    pixels_too_much = parseInt(image_file.height_orig - (image_file.width_orig/ratio_new)); 
    geometry = image_file.width_orig + 'x' + (image_file.width_orig/ratio_new); 
    geometry += "+0+" + parseInt(pixels_too_much/2)+"\!"; 
} 
im.convert([image_file.path, '-crop', geometry, '-resize', width + 'x' + height, thumb_path],function(){});