Resize to fit in a box and set background to black on “empty” part

可紊 提交于 2019-12-22 03:43:19

问题


I'm trying to obtain this result: fixed box size (133x100), the image should be resized but not stretched to fit inside that box, the empty space should be filled with black.

I'm actually trying with this command:

convert -background black -gravity center -extent 133x100 from.jpg to.jpg

However instead of fitting the image inside the requested box, I obtain a crop of the image. How to obtain the requested result? I'm digging into documentation but there are a lot of options and I still didn't find (I think) the one that I require.


回答1:


Looks like I've found the solution by myself with this link: http://www.imagemagick.org/Usage/thumbnails/#fit_summery

And this code solved my issue:

convert from.jpg -thumbnail 133x100 -background black -gravity center -extent 133x100 to.jpg


来源:https://stackoverflow.com/questions/18514083/resize-to-fit-in-a-box-and-set-background-to-black-on-empty-part

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!