當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript gm類代碼示例

本文整理匯總了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');
    }
});
開發者ID:triniwiz,項目名稱:mojichat-api,代碼行數:52,代碼來源:users.ts

示例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);
	});
}
開發者ID:syuilo,項目名稱:misskey-core,代碼行數:25,代碼來源:server.ts

示例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);
    }
  });
}
開發者ID:DallanQ,項目名稱:rxjs,代碼行數:27,代碼來源:painter.ts

示例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)
     })
 })
開發者ID:aheinrich,項目名稱:websocket-image-server,代碼行數:11,代碼來源:image.controller.ts

示例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
		});
	});
});
開發者ID:Tosuke,項目名稱:Misskey-API,代碼行數:12,代碼來源:add-file-to-album.ts

示例6: gm

 return mio.promiseUnsafe<mio.IBlob>(callback => gm(image as any).sharpen(5, 1.4).normalize().toBuffer(callback));
開發者ID:murraypaul,項目名稱:mangarack,代碼行數:1,代碼來源:imageService.ts


注:本文中的gm類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。