node.js - node.js .thumb() 的 gm 未切割精确尺寸
node.js - gm for node.js .thumb() does not cut exact size
GraphicsMagick for node.js有一个制作缩略图的方法,在文档中是这样写的
gm("img.png").thumb(width, height, outName, quality, callback)
宽度和高度是"minimum value"? http://aheckmann.github.io/gm/docs.html#thumb
该函数未生成指定的确切大小。如果我输入
gm("img.png").thumb(200, 200, ...)
我将有机会获得以下尺寸:
- 200x200
- 200x199
- 199x200
如何使用 gm 制作精确尺寸的缩略图? 请帮忙:(
使用.thumb()
函数制作缩略图后,使用.extent(width, height)
。
在您的情况下,宽度和高度都将是 200。这将在 200x200 canvas 上绘制图片,如果纵横比与此尺寸不匹配,它会自动居中。
我编写此示例代码是为了在不使用 .thumb() 函数的情况下从不符合纵横比要求的图像创建 200x200 缩略图。选项是 {height: 200, width: 200}
inputImage = inputImage.resize(options.width, options.height, "^"); //^ is the type of resize string
inputImage = inputImage.gravity("Center");
inputImage = inputImage.extent(options.width, options.height);
输入图像 - https://www.travelalaska.com/~/media/Images/Travel%20Alaska/Content/HomePage/GlacierBay.jpg
输出图像 - http://i.stack.imgur.com/cARDo.png
GraphicsMagick for node.js有一个制作缩略图的方法,在文档中是这样写的
gm("img.png").thumb(width, height, outName, quality, callback)
宽度和高度是"minimum value"? http://aheckmann.github.io/gm/docs.html#thumb
该函数未生成指定的确切大小。如果我输入
gm("img.png").thumb(200, 200, ...)
我将有机会获得以下尺寸:
- 200x200
- 200x199
- 199x200
如何使用 gm 制作精确尺寸的缩略图? 请帮忙:(
使用.thumb()
函数制作缩略图后,使用.extent(width, height)
。
在您的情况下,宽度和高度都将是 200。这将在 200x200 canvas 上绘制图片,如果纵横比与此尺寸不匹配,它会自动居中。
我编写此示例代码是为了在不使用 .thumb() 函数的情况下从不符合纵横比要求的图像创建 200x200 缩略图。选项是 {height: 200, width: 200}
inputImage = inputImage.resize(options.width, options.height, "^"); //^ is the type of resize string
inputImage = inputImage.gravity("Center");
inputImage = inputImage.extent(options.width, options.height);
输入图像 - https://www.travelalaska.com/~/media/Images/Travel%20Alaska/Content/HomePage/GlacierBay.jpg
输出图像 - http://i.stack.imgur.com/cARDo.png