本文整理匯總了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)
});