本文整理匯總了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);
});
}
示例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();
}
}
}
示例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);
});
});
});
示例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)
}
});
示例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()
}
})
})
示例6: Promise
await new Promise((resolve, reject) => {
gm(ProjectPath.FrontendFolder + '/assets/icon.png').size((err: Error) => {
if (err) {
return reject(err.toString());
}
return resolve();
});
});
示例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();
}
}
}
示例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');
});
},