我想调整大小的图片在上传与流星CollectionFS。但我想根据图像尺寸来调整尺寸。例如,我希望将1000x500大小的图像调整为1024x512,而将60x100调整为64x128 --为此,我需要了解源维度。
我的代码是基于CollectionFS 文档提供的代码
var createThumb = function(fileObj, readStream, writeStream) {
// Transform the image into a 10x10px thumbnail
gm(readStream, fileObj.name()).resize('10', '10').stream().pipe(writeStream);
};我如何在这里获得源维度,以使我的调整大小目标动态?也许有一些图形化的功能?
发布于 2016-02-29 08:01:16
有一个异步GraphicsMagick函数,用于返回图像的大小(维度)。
gm(readStream).size({ bufferStream: true }, function(err, value) {
var w = 100, h = 100;
//modify logic here to set the desired output width/height, based on the source width/height
if (value.width == 60 && value.height == 100) {
w = 64;
h = 128;
}
//"this" is the gm context, so you can chain gm functions to "this" inside the size callback.
this.resize(w, h).stream().pipe(writeStream);
});“gm国家预防机制一揽子计划”页面中关于以下内容的说明:
理解:在处理输入流和任何‘标识’操作(大小、格式等)时,如果还需要转换(写()或后的图像),则必须传递“{:true}”--注意:这会在内存中缓冲readStream!
https://stackoverflow.com/questions/35687890
复制相似问题