Resizing the image with padding using convert on ubuntu

前端 未结 1 1742
孤独总比滥情好
孤独总比滥情好 2021-02-05 09:27

I am using the convert command for resizing the image

There are two versions

Following is the first one, the resultant image maintains the aspect ratio but the i

1条回答
  •  鱼传尺愫
    2021-02-05 10:02

    You need to use -extent to set the size of the canvas directly after you have resized, and the newly created area will be filled with whatever you set the -background to.

    So, if you want the padding to be magenta, do this:

    convert image.png -resize 100x100 -background "rgb(255,0,255)" -extent 100x100 out.png
    

    If you want your image to appear "in the middle" of the output image, with the padding evenly spaced around the sides, add in -gravity center like this:

    convert image.png -resize 100x100 -gravity center -background "rgb(255,0,255)" -extent 100x100 out.png
    

    So, if we start with a wide blue image, that is 300x100 and has no chance of fitting properly in a square, as follows:

    enter image description here

    and we resize it with this:

    convert image.png -resize 100x100 -gravity center -background "rgb(255,0,255)" -extent 100x100 out.png
    

    we will get this

    enter image description here

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