本文整理汇总了TypeScript中jimp.read函数的典型用法代码示例。如果您正苦于以下问题:TypeScript read函数的具体用法?TypeScript read怎么用?TypeScript read使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getDimensions
/**
* Gets dimension of first image in folder.
* assumes that all images in folder are the same size
* @param dir
* @param callback
*/
function getDimensions(dir: string, callback: Function): void {
let file = fs.readdirSync(dir)[0];
jimp.read(dir + file, function (err: any, img: any) {
if (err) throw err;
callback(null, {width: img.bitmap.width, height: img.bitmap.height});
});
}
示例2: getCaptchaRegion
async getCaptchaRegion(clientOffset:{top:number,left:number}): Promise<any> {
const img = await screenshot();
const image = await Jimp.read(img);
image.crop(clip.x+clientOffset.left, clip.y + clientOffset.top, clip.w, clip.h);
return new Promise((resolve, reject)=>{
image.getBase64(Jimp.MIME_PNG, (e, d) => {
resolve("" + d);
});
})
}
示例3: manipulateImage
export async function manipulateImage({
img,
output,
actions,
verbose,
loadFont: font
}: ICliOptions) {
log(` đˇ Loading source image: ${img} ...`, verbose);
const image = await Jimp.read(img);
await processImage(image, font, actions, output, verbose);
}
示例4: getEventDocs
public getEventDocs(req: express.Request, res: express.Response): void {
const input: EventDocInputModel = req.body;
if (input.organizerClubUrl) {
Jimp.read(input.organizerClubUrl).then((imageData: Jimp) => {
imageData.getBuffer(Jimp.MIME_PNG, ((error, jpegImage) => {
if (error) {
this.handleResponse(req, res,
'Das Logo von ' + input.organizerTeamName + ' kann nicht verwendet werden.', null);
} else {
this._floorballzTournamentDocumentService.getEventDocs(input, jpegImage).pipe(res);
}
}));
}).catch(() => {
this.handleResponse(req, res,
'Das Logo von ' + input.organizerTeamName + ' kann nicht herunter geladen werden.', null);
});
} else {
this._floorballzTournamentDocumentService.getEventDocs(input, undefined).pipe(res);
}
}
示例5: reject
const future = new Promise<string>(async (resolve, reject) => {
await Jimp.read(await file.toBuffer(), (err, image) => {
if (err) {
return reject(err)
}
const qrCodeImageArray = new Uint8ClampedArray(image.bitmap.data.buffer)
const qrCodeResult = jsQR(
qrCodeImageArray,
image.bitmap.width,
image.bitmap.height,
)
if (qrCodeResult) {
return resolve(qrCodeResult.data)
} else {
return reject(new Error('WXGetQRCode() qrCode decode fail'))
}
})
})
示例6: function
function(file: string, asyncCallback: Function) {
jimp.read(dir + file, function (err: any, img: any) {
if (err) throw err;
images.push(img.bitmap.data);
process.stdout.write('.');
// img.scan(0, 0, img.bitmap.width, img.bitmap.height, function (x: number, y: number, idx: number) {
// // x, y is the position of this pixel on the image
// // idx is the position start position of this rgba tuple in the bitmap Buffer
// // this is the image
//
// imgPixels.push(this.bitmap.data[idx]); // Red
// imgPixels.push(this.bitmap.data[idx + 1]); // Green
// imgPixels.push(this.bitmap.data[idx + 2]); // Blue
//
// // rgba values run from 0 - 255
// // e.g. this.bitmap.data[idx] = 0; // removes red from this pixel
// });
// images[index] = imgPixels;
asyncCallback();
});
},
示例7: require
import * as Jimp from "jimp";
const _Jimp = require("jimp");
// open a file called "lenna.png"
Jimp.read("lenna.png", (err, lenna) => {
if (err) throw err;
lenna.resize(256, 256) // resize
.quality(60) // set JPEG quality
.greyscale() // set greyscale
.write("lena-small-bw.jpg"); // save
});
// Using promises
Jimp.read("lenna.png")
.then(lenna => {
lenna.resize(256, 256) // resize
.quality(60) // set JPEG quality
.greyscale() // set greyscale
.write("lena-small-bw.jpg"); // save
})
.catch(err => {
console.error(err);
});
// Basic usage
Jimp.read("./path/to/image.jpg", (err, image) => {
// do stuff with the image (if no exception)
});