Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should create a proper colored preview from non-sRGB original', async () => {
const newAttachment = await createAndCheckAttachment(files.colorprofiled, post, user)
// original colors
{
const original = promisifyAll(gm(newAttachment.getPath()))
const buffer = await original.resize(1, 1).toBufferAsync('RGB')
buffer.length.should.be.equal(3)
buffer[0].should.be.within(191, 193)
buffer[1].should.be.within(253, 255)
buffer[2].should.be.within(127, 129)
}
// thumbnail colors
{
const thumbnailFile = newAttachment.getResizedImagePath('t')
thumbnailFile.should.be.a.file().and.not.empty
const thumbnail = promisifyAll(gm(thumbnailFile))
const buffer = await thumbnail.resize(1, 1).toBufferAsync('RGB')
.size(function (err, size) {
if (!err && size.width * size.height > width * height) {
gm(`../../components/Work/Repo/img/${image}`)
.resize(width, height)
.noProfile()
.write(`../../components/Work/Repo/img/${image}`, function (err) {
if (!err)
// console.log('done')
accept()
})
}
})
})
graphicMagickBaseCommand(stream, filename) {
let { density, size, quality, compression } = this.options
const width = size.split(/x/i)[0]
const height = size.split(/x/i)[1]
if (!height) {
return gm(stream, filename)
.density(density, density)
.resize(size)
.quality(quality)
.compress(compression)
}
return gm(stream, filename)
.density(density, density)
.resize(width, height)
.quality(quality)
.compress(compression)
}
fs.existsSync(input_file_name, exists => {
if (exists) {
gm(input_file_name)
.resize(500, 240, '!')
.backdrop()
.write(output_file_name, err => console.log(err))
} else {
console.log('File not exists.')
}
})
})
public async init(): Promise {
try {
const metadata = await this.sharp.metadata();
this.width = metadata.width;
this.height = metadata.height;
this.format = metadata.format;
} catch (err) {
logger.warn(null, '[Image.init] Could not read metadata from buffer (%s), using GM to read image.', err.message);
this.gm = gm(this.data);
const metadata = await this.gmIdentify();
this.format = metadata.format.toLowerCase();
this.width = metadata.size.width;
this.height = metadata.size.height;
const data = await new Promise((resolve, reject) => {
const buffers: Buffer[] = [];
this.gm.setFormat('jpeg').stream().on('error', reject)
.on('data', (buf: Buffer) => buffers.push(buf as Buffer))
.on('end', () => resolve(Buffer.concat(buffers)))
.on('error', reject);
});
this.data = undefined;
this.sharp = sharp(data);
}
this.stats = await this.sharp.stats();
return this;
public static async isExifRotated(path: string): Promise {
try {
const gm = GM(path);
const orientation: string = (await Util.promisify(gm.orientation.bind(gm))()) as any;
switch (orientation.toLowerCase()) {
case 'topleft':
case 'unknown':
return false;
default:
return true;
}
} catch (err) {
console.error('isExifRotated failed', path, err);
return false;
}
}
private static async getImageMetadata(absolutePath: string): Promise
function generateFrame(frameData, width, height, opacity, pixelSize) {
const frame = frameData.map(elem => ({
x: elem.x,
y: elem.y,
color: elem.color
}));
const BGCOLOR = '#000000';
const FILLCOLOR = `0${Math.round((1 - opacity) * 255).toString(16)}`.slice(
-2
);
const gmImg = gm(width, height, `${BGCOLOR}${FILLCOLOR}`);
for (let i = 0; i < frame.length; i++) {
const aux = frame[i];
gmImg
.fill(aux.color)
.drawRectangle(aux.x - pixelSize, aux.y - pixelSize, aux.x, aux.y);
}
return gmImg;
}
pixels: variants[req.query.variant || 'wide'],
reverse: (req.query.reverse === 'true') ? true : false
}, (err, ascii) => {
if (err) {
return next(new Error(`Unable to create an ASCII art for ${imagesrc}`));
}
if (req.query.trim !== 'false') {
ascii = ascii.replace(/\n^\s*$/gm, '');
}
res.setHeader('content-type', 'text/plain; charset=us-ascii');
res.send(`${ascii}\n`);
});
break;
default:
gm(request(imagesrc))
.resize(params.width, params.height)
.stream(req.params.format)
.pipe(res);
break;
}
},