通过保持宽高比nodejs将图像调整为精确大小 [英] Resize image to exact size by maintaining aspect ratio nodejs
本文介绍了通过保持宽高比nodejs将图像调整为精确大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过保持长宽比并使用nodejs透明填充空白空间来将图像调整为精确大小.
I want to resize image to an exact size by maintaining aspect ratio and filling the empty space with transparency using nodejs.
我可以使用画布来做到这一点.但是由于某些服务器操作系统问题,我无法使用canvas.
I am able to do it using canvas. But due to some server os issues I can not use canvas.
我尝试使用imageMagick和gm.但是找不到像这样的任何选择.请告诉我一种方法.
I tried with imageMagick and gm. But couldn't find any option like these. Please show me a way to do this.
先谢谢了.
推荐答案
在ImageMagick中,您可以通过以下方式调整大小并填充到确切的大小:
In ImageMagick, you can resize and fill to the exact size by
convert image -resize WxH -background none -gravity center -extent WxH output
输入:
在这里,我将背景变黑,以便您查看是否将其填满.
Here I will make the background black so you can see that if fills it out.
convert lena.jpg -resize 400x300 -background black -gravity center -extent 400x300 lena1.jpg
这篇关于通过保持宽高比nodejs将图像调整为精确大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文