MCPcopy Create free account
hub / github.com/coderwhy/coderhub / pictureResize

Function pictureResize

src/middleware/file.middleware.js:17–37  ·  view source on GitHub ↗
(ctx, next)

Source from the content-addressed store, hash-verified

15const pictureHandler = pictureUpload.array('picture', 9);
16
17const 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
39module.exports = {
40 avatarHandler,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected