(ctx, next)
| 15 | const pictureHandler = pictureUpload.array('picture', 9); |
| 16 | |
| 17 | const pictureResize = async (ctx, next) => { |
| 18 | try { |
| 19 | // 1.获取所有的图像信息 |
| 20 | const files = ctx.req.files; |
| 21 | |
| 22 | // 2.对图像进行处理(sharp/jimp) |
| 23 | for (let file of files) { |
| 24 | const destPath = path.join(file.destination, file.filename); |
| 25 | console.log(destPath); |
| 26 | Jimp.read(file.path).then(image => { |
| 27 | image.resize(1280, Jimp.AUTO).write(`${destPath}-large`); |
| 28 | image.resize(640, Jimp.AUTO).write(`${destPath}-middle`); |
| 29 | image.resize(320, Jimp.AUTO).write(`${destPath}-small`); |
| 30 | }); |
| 31 | } |
| 32 | |
| 33 | await next(); |
| 34 | } catch (error) { |
| 35 | console.log(error); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | module.exports = { |
| 40 | avatarHandler, |
nothing calls this directly
no outgoing calls
no test coverage detected