Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const file = ctx.request.body.files && ctx.request.body.files.file
let user = ctx.req.user
if (!user) throw new NotFoundError('No active user session')
if (!file) throw new InvalidBodyError('Request doesn\'t include an image file')
user = await User.findOne({where: {id: user.id}})
const newFilePath = file.path + '_square.' + file.type.split('/')[1]
// Resize
try {
const image = await jimp.read(file.path)
image.cover(200, 200, jimp.HORIZONTAL_ALIGN_CENTER, jimp.VERTICAL_ALIGN_TOP)
.write(newFilePath, err => {
if (err) {
console.log('auth:197', newFilePath, err)
}
})
} catch (e) {
throw new InvalidBodyError('Unsopported image format')
}
user.profile_picture = path.basename(newFilePath)
try {
await user.save()
} catch (e) {
console.log('auth.js:191', e)
}
async function createCover() {
// load font and our base cover image
// we put subreddit into this image
const font = await Jimp.loadFont(Jimp.FONT_SANS_64_BLACK);
const image = await Jimp.read("./cover/Reddit2Ebook.jpg");
await image.print(
font,
0, // x
600, // y
{
text: subreddit,
alignmentX: Jimp.HORIZONTAL_ALIGN_CENTER,
alignmentY: Jimp.VERTICAL_ALIGN_MIDDLE
},
782, // maxWidth (use same width as base cover image to center correctly)
200 // maxHeight
)
.quality(80) // set JPEG quality. We don't need very high quality output.
.write("./cover/cover.jpg");
}
const Jimp = require('jimp');
const RESIZE_MODES = [
Jimp.HORIZONTAL_ALIGN_LEFT,
Jimp.HORIZONTAL_ALIGN_CENTER,
Jimp.HORIZONTAL_ALIGN_RIGHT,
Jimp.VERTICAL_ALIGN_TOP,
Jimp.VERTICAL_ALIGN_MIDDLE,
Jimp.VERTICAL_ALIGN_BOTTOM
];
const FIELD_CONFIGS = {
width: {
type: 'integer',
min: 1,
max: 4096,
required: true,
default: 150
},
height: {