• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript gm.default函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中gm.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了default函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: _createGdImage

  /**
   *  Creates image object in memory using GD library
   */
  private _createGdImage(fileName: string, done: DoneCallback) {
    gm(fileName).format((err: any, format: string) => {
      if (err) {
        return done('createGdImage error: ' + err);
      }

      let image = null;
      switch (format) {
        case 'JPEG': {
          image = gd.createFromJpeg(fileName);
          break;
        }
        case 'PNG': {
          image = gd.createFromPng(fileName);
          break;
        }
        case 'GIF': {
          image = gd.createFromGif(fileName);
          break;
        }
        default: {
          return done(`Unknown image format: ${format}`);
        }
      }

      done(null, image);
    });
  }
开发者ID:apedyashev,项目名称:opticrop-node,代码行数:31,代码来源:opticrop.ts


示例2: rollbackPreProcess

	/**
	 * Since we need to persist preprocessing changes before validating, we also need a way to
	 * roll them back when validations fail.
	 *
	 * @param {Context} ctx Koa context
	 */
	protected async rollbackPreProcess(ctx: Context): Promise<void> {

		if (ctx.query.rotate) {

			// validate input format
			const rotations = this.parseRotationParams(ctx.query.rotate);

			// validate input data
			for (const rotation of rotations) {
				const file = await state.models.File.findOne({ id: rotation.file }).exec();
				if (!file) {
					throw new ApiError('Cannot rollback non-existing file "%s".', rotation.file).status(404);
				}
				const src = await this.backupFile(ctx.state, file);

				// do the actual rotation
				if (rotation.angle !== 0) {
					delete file.preprocessed.unvalidatedRotation;
					logger.info(ctx.state, '[ReleaseApi.rollbackPreprocess] Rolling back rotated file "%s" to %s째.', file.getPath(ctx.state), file.preprocessed.rotation);
					await (gm(src).rotate('black', file.preprocessed.rotation) as any).writeAsync(file.getPath(ctx.state));
				}

				// update metadata
				const metadata = await Metadata.readFrom(ctx.state, file, file.getPath(ctx.state));
				await state.models.File.findByIdAndUpdate(file._id, {
					metadata,
					file_type: file.file_type,
					preprocessed: file.preprocessed,
				}).exec();
			}
		}
	}
开发者ID:freezy,项目名称:node-vpdb,代码行数:38,代码来源:release.abstract.api.ts


示例3:

			}, (getFileErr: any, response: http.IncomingMessage, body: Buffer) => {
				if (getFileErr !== null) {
					console.error(getFileErr);
					return res.status(500).send(getFileErr.body);
				}
				gm(body, file.name)
				.crop(trimW, trimH, trimX, trimY)
				.toBuffer('png', (err: Error, buffer: Buffer) => {
					if (err !== null) {
						console.error(err);
						return res.status(500).send('something-happened');
					}
					requestApi('album/files/upload', {
						file: {
							value: buffer,
							options: {
								filename: `${file.name}.cropped.png`,
								contentType: 'image/png'
							}
						}
					}, req.user, true).then((albumFile: any) => {
						requestApi('account/avatar/update', {
							'file-id': albumFile.id
						}, req.user).then((me: Object) => {
							res.send('success');
						}, (updateErr: any) => {
							return res.status(500).send(updateErr.body);
						});
					}, (uploadErr: any) => {
						return res.status(500).send(uploadErr.body);
					});
				});
			});
开发者ID:sagume,项目名称:Misskey-Web,代码行数:33,代码来源:update.ts


示例4: if

      sails.hooks.gfs.findOne({_id: image.originalId}, function (err, file) {
	      if (err) return reject(err);
        else if (!file) return reject(new Error("File with object id " + image.originalId + " not found"));

        // Create our GridFS read and write streams
        var readStream = sails.hooks.gfs.createReadStream({_id: image.originalId});
        readStream.once('error', reject);

        var newId = new Mongo.ObjectID();
        var writeStream = sails.hooks.gfs.createWriteStream({
          _id: newId,
          filename: file.name,
          mode: 'w',
          chunkSize: 1024 * 1024,
          content_type: file.mimetype
        });
        writeStream.once('error', reject);
        if (krake) { // Use Kraken.io
          //TODO https://github.com/kraken-io/kraken-node#how-to-use
        } else { // Use Graphics Magick
          GM(readStream)
            .resize(width, height, "!")
            .noProfile()
            .stream()
            .pipe(writeStream)
            .once('close', () => resolve(newId))
            .once('error', reject)
        }
      });
开发者ID:ModMountain,项目名称:web-old,代码行数:29,代码来源:FileService.ts


示例5: gm

      .size(source, (error, original)=> {
        var desired_aspect = new_width / new_height
        var orig_aspect = original.width / original.height
        var trim

        var operation = gm(source)
          .options({imageMagick: true})

        if (desired_aspect > orig_aspect) {
          trim = original.height - (original.width / desired_aspect)
          operation = operation.crop(original.width, original.height - trim, 0, trim / 2)
        }
        else {
          trim = original.width - (original.height * desired_aspect)
          operation = operation.crop(original.width - trim, original.height, trim / 2, 0)
        }

        operation.resize(new_width, new_height, '!')
          .write(dest, function (err) {
            if (err) {
              console.error('error writing file ' + dest, err)
              def.reject(err)
            }
            else {
              def.resolve()
            }
          })
      })
开发者ID:silentorb,项目名称:vineyard-cellar,代码行数:28,代码来源:cellar.ts


示例6: Promise

 await new Promise((resolve, reject) => {
   gm(ProjectPath.FrontendFolder + '/assets/icon.png').size((err: Error) => {
     if (err) {
       return reject(err.toString());
     }
     return resolve();
   });
 });
开发者ID:bpatrik,项目名称:PiGallery2,代码行数:8,代码来源:ConfigDiagnostics.ts


示例7: preProcess

	/**
	 * Pre-processes stuff before running validations.
	 *
	 * Currently, the only "stuff" is rotation of referenced media.
	 * @param {Context} ctx Koa context
	 * @param {string[]} allowedFileIds Database IDs of file IDs of the current release that are allowed to be preprocessed.
	 * @returns {Promise}
	 */
	protected async preProcess(ctx: Context, allowedFileIds: string[]): Promise<void> {

		if (ctx.query.rotate) {

			// validate input format
			const rotations = this.parseRotationParams(ctx.query.rotate);

			// validate input data
			for (const rotation of rotations) {
				const file = await state.models.File.findOne({ id: rotation.file }).exec();
				if (!file) {
					throw new ApiError('Cannot rotate non-existing file "%s".', rotation.file).status(404);
				}

				if (!allowedFileIds.includes(file._id.toString())) {
					throw new ApiError('Cannot rotate file %s because it is not part of the release (%s).', file.id, file._id).status(400);
				}
				if (file.getMimeCategory() !== 'image') {
					throw new ApiError('Can only rotate images, this is a "%s".', file.getMimeCategory()).status(400);
				}
				if (!['playfield', 'playfield-fs', 'playfield-ws'].includes(file.file_type)) {
					throw new ApiError('Can only rotate playfield images, got "%s".', file.file_type).status(400);
				}
				const src = await this.backupFile(ctx.state, file);

				// do the actual rotation
				if (rotation.angle !== 0) {
					file.preprocessed = file.preprocessed || {};
					file.preprocessed.rotation = file.preprocessed.rotation || 0;
					file.preprocessed.unvalidatedRotation = (file.preprocessed.rotation + rotation.angle + 360) % 360;

					logger.info(ctx.state, '[ReleaseApi.preProcess] Rotating file "%s" %s째 (was %s째 before, plus %s째).', file.getPath(ctx.state), file.preprocessed.unvalidatedRotation, file.preprocessed.rotation, rotation.angle);

					const img = gm(src);
					img.rotate('black', -file.preprocessed.unvalidatedRotation);
					await new Promise<void>((resolve, reject) => {
						const writeStream = createWriteStream(file.getPath(ctx.state));
						writeStream.on('finish', resolve);
						writeStream.on('error', reject);
						img.stream().on('error', reject).pipe(writeStream).on('error', reject);
					});
					logger.info(ctx.state, '[ReleaseApi.preProcess] Rotated file written to %s.', file.getPath(ctx.state));
				}

				// update metadata
				const metadata = await Metadata.readFrom(ctx.state, file, file.getPath(ctx.state));
				await state.models.File.findOneAndUpdate({ _id: file._id }, {
					metadata,
					file_type: 'playfield-' + (metadata.size.width > metadata.size.height ? 'ws' : 'fs'),
					preprocessed: file.preprocessed,
				}).exec();
			}
		}
	}
开发者ID:freezy,项目名称:node-vpdb,代码行数:62,代码来源:release.abstract.api.ts


示例8: gm

 // png
 (callback) => {
     if (!params.png) return callback();
     let dest = Util.replaceExtension(params.dest, 'png');
     let file = gapis.storage.createFile(dest);
     results.png = gapis.storage.getPublicUrl(file);
     let writeStream = file.createWriteStream({ gzip: true });
     gm(params.src).density(300, 300).setFormat("png").stream().pipe(writeStream).on('finish', (err) => {
         if (err) return callback(err);
         if (file) return file.makePublic(callback);
         callback('gm failed to create png file');
     });
 },
开发者ID:zaksie,项目名称:gotouch,代码行数:13,代码来源:graphics.ts



注:本文中的gm.default函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript goita-core.Util类代码示例发布时间:2022-05-25
下一篇:
TypeScript gloo2.VertexBuffer类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap