【问题标题】:Resize image to one resolution将图像大小调整为一种分辨率
【发布时间】:2011-01-21 19:34:45
【问题描述】:

我有一堆不同分辨率的图像。 还有横向和纵向图片的混合。我需要将图像大小调整为一种分辨率(1024x768)。如果我有一张纵向图片,最大高度需要为 768,而我的横向图片必须有最大宽度为 1024。

结束的空间必须变黑。 现在我使用mogrify -resize 1024x768 -verbose *.jpg

我知道我可以使用 1024x!768 ,但就像我说的那样,我使用的是不同类型的图片。 我的 exif 信息也不包含有关图片是否为横向的信息。

【问题讨论】:

    标签: linux image imagemagick mogrify


    【解决方案1】:

    我使用 ImageMagick 来完成这些任务。安装后,您有“转换”命令,这是非常常见的,并且可以轻松完成您的任务。

    【讨论】:

    • Daniel:我确实也看到了那个工具。您对我需要使用哪些参数有什么建议吗?
    • 转换 in.jpg -resize 1024x768 out.jpg!有很多选择。见imagemagick.org/Usage/resize
    • 现在我有:convert -gravity center -resize 1024x768 -background black -extent 1024x768 * 但这仍然会调整 x 或 y 轴的大小,它没有保留横向/纵向的概念
    【解决方案2】:

    您必须裁剪图像以获得相同的纵横比,然后您可以调整图像大小以获得所需的分辨率。使用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(){});
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-27
      • 2013-02-25
      • 2014-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-07
      相关资源
      最近更新 更多