Graphicsmagick autoOrient()。size()在node.js库中给出了翻转的图像大小
图像自动定位后,如何获取图像大小?
大小依然给予自动定向的大小,而不是旋转后的大小。 (所以x和y的尺寸翻转)。
var original = gm(response.Body).autoOrient(); original.size(function (err, size) { if (err) { console.error(err); return res.status(500).send(err); } resize_photo(size, max_size, original, function (err, photo) { res.setHeader('Content-Type', 'image/jpeg'); res.send(photo); }); });
我有同样的问题,并发现,如果我写出autoOrient文件,然后读回来,size()读取翻转的尺寸。
//Ignoring errors gm('/images/original.jpg').autoOrient().write('/images/autoOriented.jpg', function (err) { gm('/images/autoOriented.jpg').size(function(err, size) { console.log('size: ', size); }); });
一种解决方法是写入缓冲区,然后调用.size
像这样:
gm(response.Body).autoOrient().toBuffer(function (err, buffer) { if (!err) { gm(buffer).size(function (err, size) { if (!err) { console.log(size); } }); } });
注意:这是.size
的,因为.size
在新的自动定向缓冲区上运行图像magick命令identify
,而不是原始文件或原始缓冲区。