画像を切り抜いて同じアスペクト比にする必要があります。その後、画像のサイズを変更して希望の解像度にすることができます。 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(){});
ダニエル:私はそのツールを実際に見ました。私は使用する必要があるいくつかの提案がありますか? – Grezly
convert in.jpg -resize 1024x768 out.jpg!多くのオプションがあります。 http://www.imagemagick.org/Usage/resizeを参照してください – Daniel
今私は持っています:変換 - 重力中心 - 解像度1024x768 - 背景黒 - 倍率1024x768 *しかし、これはまだxまたはy asxisのサイズを変更しません、風景/肖像画の概念 – Grezly