Imagemagick convert resize then crop

前端 未结 2 1509
情话喂你
情话喂你 2021-01-31 16:39


I have over 1000 images on different resolutions, (for example 1234x2122, 4400x5212 , etc) and I want to convert all them to fixed 100x100 size, so.

  1. first I

相关标签:
2条回答
  • 2021-01-31 17:07

    You would use the area-fill (^) geometry modifier on the -resize operation to unify the down-scale. For cropping the center, -extent with -gravity Center will work.

    convert input.jpg -resize 100x100^ \
                      -gravity Center  \
                      -extent 100x100  \
            output.jpg
    

    Update

    As Mark Setchell pointed out in the comments, the mogrify utility can be leveraged to batch convert items.

    mogrify -path ./path/to/write/results/ \
            -resize 100x100^ \
            -gravity Center  \
            -extent 100x100  \
            ./path/to/source/files/*
    

    reminder Reminder: Mogrify will overwrite original file with resulting image(s), unless you set the -path parameter.

    0 讨论(0)
  • 2021-01-31 17:22

    To keep the aspect ratio and don't fill anything (extent), rather crop from the longer edge which is out of aspect you could do

    convert input.jpg -resize 100x100^ \
                      -gravity Center  \
                      -crop 100x100+0+0 +repage  \
            output.jpg
    

    with option to crop more from one side if you like

    0 讨论(0)
提交回复
热议问题