Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
// if not in a proper raid channel, cancel out immediately
const regionId = await RegionHelper.getRegionId(message.channel.id)
.catch(error => log.error(error));
if (!regionId) {
log.info('Not in a region channel, won\'t attempt to process');
return;
}
// show users the bot is starting to process their image
message.react('🤔')
.catch(err => log.error(err));
Jimp.read(url)
.then(image => {
if (!image) {
return;
}
id = uuidv1();
// resize to some standard size to help tesseract
log.debug("Scaling image to standard size...");
newImage = image.scaleToFit(1440, 2560, Jimp.RESIZE_HERMITE);
log.debug("...done");
// determine if image is a raid image or not
let screenshotType = ImageProcessing.SCREENSHOT_TYPE_NONE;
// check for pink "time remaining" pixels
newImage.scan(newImage.bitmap.width / 2, (newImage.bitmap.height / 4.34) - 80, 1, 160, function (x, y, idx) {
checkProxyWhitelist(url, function(trusted) {
if (trusted) {
jimp.read(url, function(err, image) { // Gets the image file from the URL
if (err) {
utils.handleError(err, res);
} else if (image) {
image.getBuffer(jimp.MIME_PNG, function(err2, image2) { // Buffers the image so it sends correctly
if (err2) {
utils.handleError(err2, res);
} else {
res.setHeader('Content-type', 'image/png'); // Makes sure its a png
res.send(image2); // Sends the image to the browser.
}
});
} else {
res.status(404).send();
}
});
} else {
async function saveFile (buffer, pathToFile) {
const jimpFile = await jimp.read(buffer)
const { width, height } = jimpFile.bitmap
const writtenFile = await jimpFile.write(pathToFile)
/* istanbul ignore if */
if (!writtenFile) throw new Error('There was an erroring saving your file.')
return { width, height }
}
const isOnline = await this.cli_.isOnline();
const fontTimeoutMs = isOnline ? SELENIUM_FONT_LOAD_WAIT_MS : 500;
await driver.get(url);
await driver.wait(until.elementLocated(By.css('[data-fonts-loaded]')), fontTimeoutMs).catch(() => 0);
if (delayMs > 0) {
await driver.sleep(delayMs);
}
const uncroppedImageBuffer = Buffer.from(await driver.takeScreenshot(), 'base64');
const croppedImageBuffer = await this.imageCropper_.autoCropImage(uncroppedImageBuffer);
const uncroppedJimpImage = await Jimp.read(uncroppedImageBuffer);
const croppedJimpImage = await Jimp.read(croppedImageBuffer);
const {width: uncroppedWidth, height: uncroppedHeight} = uncroppedJimpImage.bitmap;
const {width: croppedWidth, height: croppedHeight} = croppedJimpImage.bitmap;
const message = `${url} > ${userAgent.alias} screenshot from ` +
`${uncroppedWidth}x${uncroppedHeight} to ${croppedWidth}x${croppedHeight}`;
this.logStatus_(CliStatuses.CROP, message);
return croppedImageBuffer;
}
it("should work with a zxing qr code with jimp", function(done) {
var buffer = fs.readFileSync(__dirname + '/image-zxing.png');
Jimp.read(buffer, function(err, image) {
if (err) {
return done(err);
}
var qr = new QrCode();
qr.callback = function(err, result) {
if (err) {
return done(err);
}
expect(copy(result)).to.deep.equal({
"result": 'Test',
"points": [
{
"count": 2,
"estimatedModuleSize": 9,
"x": 34.5,
"y": 160.5,
async getRemovedScreenshots_({expectedScreenshots, actualScreenshots}) {
/** @type {!Array} */
const removedScreenshots = [];
for (const expectedScreenshot of expectedScreenshots) {
const actualScreenshot = this.findScreenshotForComparison_({
screenshots: actualScreenshots,
screenshot: expectedScreenshot,
});
if (!actualScreenshot) {
const expectedImageUrl = expectedScreenshot.expected_image_file.public_url;
const expectedJimpImage = await Jimp.read(await this.fileCache_.getBuffer({uri: expectedImageUrl}));
const {width, height} = expectedJimpImage.bitmap;
expectedScreenshot.diff_image_result = DiffImageResult.create({
expected_image_dimensions: Dimensions.create({width, height}),
});
removedScreenshots.push(expectedScreenshot);
}
}
return removedScreenshots;
}
async analyzeComparisonResult_({expectedImageBuffer, actualImageBuffer, resembleComparisonResult, flakeConfig}) {
/** @type {!Buffer} */
const diffImageBuffer = resembleComparisonResult.getBuffer();
/** @type {!Jimp.Jimp} */ const expectedJimpImage = await Jimp.read(expectedImageBuffer);
/** @type {!Jimp.Jimp} */ const actualJimpImage = await Jimp.read(actualImageBuffer);
/** @type {!Jimp.Jimp} */ const diffJimpImage = await Jimp.read(diffImageBuffer);
function roundPercentage(rawPercentage) {
let roundPower = Math.pow(10, 1);
if (rawPercentage < 1) {
const leadingFractionalZeroDigits = String(rawPercentage).replace(/^0\.(0*).*$/g, '$1').length + 1;
roundPower = Math.pow(10, leadingFractionalZeroDigits);
}
return Math.ceil(rawPercentage * roundPower) / roundPower;
}
const diffPixelRawPercentage = resembleComparisonResult.rawMisMatchPercentage;
const diffPixelRoundPercentage = roundPercentage(diffPixelRawPercentage);
const diffPixelFraction = diffPixelRawPercentage / 100;
const diffPixelCount = Math.ceil(diffPixelFraction * diffJimpImage.bitmap.width * diffJimpImage.bitmap.height);
async run(message) {
const args = message.content.split(" ").slice(1)
await message.channel.startTyping()
let avatarurl = (message.mentions.users.size > 0 ? message.mentions.users.first().displayAvatarURL({ format: 'png' }) : message.author.displayAvatarURL({ format: 'png' })).replace('gif', 'png');
if (['jpg', 'jpeg', 'gif', 'png', 'webp'].some(x => args.join(' ').includes(x))) {
avatarurl = args.join(' ').replace(/gif|webp/g, 'png')
}
var avatar = await Jimp.read(avatarurl);
const disabled = await Jimp.read('assets/images/disabled.png');
avatar.resize(157, 157);
disabled.composite(avatar, 390, 252);
disabled.getBuffer(Jimp.MIME_PNG, async(err, buffer) => {
await message.channel.send({
files: [{
name: 'disabled.png',
attachment: buffer
}]
})
await message.channel.stopTyping()
})
return null;
}
}, function (cb) {
return Jimp.read(overlay, cb);
}], function (error, images) {
images[0].resize(maximum, Jimp.AUTO);
$('.vector').on('click', () => {
Jimp.read(imageURL, (error, image) => {
if (error) return;
const imgPath = path.join(app.getPath('temp'), 'potrace.bmp');
let binPath;
if (platform == 'darwin') {
binPath = path.join(app.getAppPath(), 'bin', 'osx', 'potrace');
} else if (platform == 'win32') {
binPath = path.join(app.getAppPath(), 'bin', 'win', 'potrace.exe');
} else {
return;
}
image.write(imgPath, () => {
execFile(binPath, ['-s', '-n', imgPath], (error, stdout) => {
if (error) return;