本文整理汇总了TypeScript中gm类的典型用法代码示例。如果您正苦于以下问题:TypeScript gm类的具体用法?TypeScript gm怎么用?TypeScript gm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了gm类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: gm
router.post('/image/profile/:id', upload.single('avatar'), userMW.verify, (req, res) => {
if ((req.userId === req.params['id']) && req.file) {
gm(req.file.path).compress("JPEG").toBuffer((err, buf) => {
r.table("users").get(req.params['id']).run(req.conn)
.then((result: any) => {
if (result && result.avatar) {
r.table("files").get(result.avatar).delete().run(req.conn)
.then(() => {
return r.table("files").insert({ file: buf }).run(req.conn)
}).then((result) => {
return r.table("users").get(req.params['id']).update({ avatar: result.generated_keys[0] }).run(req.conn)
})
.then((result) => {
res.end("Upload successful")
})
.error((err) => {
res.status(500).end('Error occured while updating profile photo');
})
} else {
r.table("files").insert({ file: buf }).run(req.conn)
.then((result) => {
return r.table("users").get(req.params['id']).update({ avatar: result.generated_keys[0] }).run(req.conn)
})
.then((result) => {
res.end("Upload successful")
})
.error((err) => {
res.status(500).end('Failed to change profile photo')
})
}
}).error((err) => {
console.log(err)
res.end('err')
})
})
} else if (req.isAdmin && req.file) {
gm(req.file.path).compress("JPEG").toBuffer((err, buf) => {
r.table("files").insert({ file: buf }).run(req.conn)
.then((result) => {
return r.table("users").get(req.params['id']).update({ avatar: result.generated_keys[0] }).run(req.conn)
})
.then((result) => {
res.end("Upload successful")
})
.error((err) => {
res.status(500).end('Failed to change profile photo')
})
})
} else {
res.status(401).end('Unauthorized');
}
});
示例2: thumbnail
async function thumbnail(data: Buffer, type: string, resize: number, res: express.Response): Promise<any> {
if (!/^image\/.*$/.test(type)) {
data = fs.readFileSync(__dirname + '/resources/dummy.png');
}
let g = gm(data);
if (resize) {
g = g.resize(resize, resize);
}
g
.compress('jpeg')
.quality(80)
.toBuffer('jpeg', (err, img) => {
if (err !== undefined && err !== null) {
console.error(err);
res.sendStatus(500);
return;
}
res.header('Content-Type', 'image/jpeg');
res.send(img);
});
}
示例3: painter
export function painter(inputStreams: TestStream[], operatorLabel: string, outputStreams: TestStream[], filename: string) {
inputStreams = sanitizeHigherOrderInputStreams(inputStreams, outputStreams);
const maxFrame = getMaxFrame(inputStreams.concat(outputStreams)) || DEFAULT_MAX_FRAME;
let allStreamsHeight = inputStreams.concat(outputStreams)
.map(measureStreamHeight(maxFrame))
.reduce(function (x, y) { return x + y; }, 0);
canvasHeight = allStreamsHeight + OPERATOR_HEIGHT;
let heightSoFar = 0;
let out: GMObject = gm(CANVAS_WIDTH, canvasHeight, '#ffffff');
inputStreams.forEach(function (streamData) {
out = drawObservable(out, maxFrame, heightSoFar, streamData, false);
heightSoFar += measureStreamHeight(maxFrame)(streamData);
});
out = drawOperator(out, operatorLabel, heightSoFar);
heightSoFar += OPERATOR_HEIGHT;
outputStreams.forEach(function (streamData) {
let isSpecial = inputStreams.length > 0 && areEqualStreamData(inputStreams[0], streamData);
out = drawObservable(out, maxFrame, heightSoFar, streamData, isSpecial);
heightSoFar += measureStreamHeight(maxFrame)(streamData);
});
out.write(filename, function (err: Error) {
if (err) {
return console.error(arguments);
}
});
}
示例4: Promise
return new Promise((resolve, reject) => {
console.log("Attempting to process image")
// let i = path.join(__dirname, "images", "image.png")
// console.log(i)
gm("images/image.png").identify( (err, value) => {
console.log(value)
resolve(value)
})
})
示例5: Promise
const getPictureProperty = (file, fileName) => new Promise((resolve, reject) => {
gm(file, fileName).size((getSizeErr: any, whsize: any) => {
if (getSizeErr !== undefined && getSizeErr !== null) {
console.error(getSizeErr);
return resolve();
}
return resolve({
width: whsize.width,
height: whsize.height
});
});
});
示例6: gm
return mio.promiseUnsafe<mio.IBlob>(callback => gm(image as any).sharpen(5, 1.4).normalize().toBuffer(callback));