当我上传多页 pdf 文件然后多次生成缩略图时,我遇到问题。
我的代码如下
var image = random() + '.png';
imagename = 'uploads/document_thumb/' + image;
var pathToFile = path.join(__dirname, req.files[i].path)
, pathToSnapshot = path.join(__dirname, '/uploads/document_thumb/' + image);
im.resize({
srcPath: pathToFile
, dstPath: pathToSnapshot
, width: 150
, height: 150
, quality: 0
, gravity: "North"
},
function (err, stdout, stderr) {
if (err) {
console.log(err);
}
console.log('resized image', pathToSnapshot);
});
如何设置只生成一页缩略图。
我使用 GraphicsMagick 生成 Pdf 文件的缩略图。
var gm = require('gm');
var image = random() + '.png';
var pathToFile = path.join(__dirname, req.files[i].path);
var pathToSnapshot = path.join(__dirname, '/uploads/document_thumb/' + image);
gm(pathToFile).thumb(
150, // Width
150, // Height
pathToSnapshot, // Output file name
40, // Quality from 0 to 100
function (error, stdout, stderr, command) {
if (!error) {
console.log(command);
}
else {
console.log(error);
}
}
);