Commit 1c9db343 authored by nanahira's avatar nanahira

resize image

parent 8d26e67d
Pipeline #48 failed with stages
FROM node
FROM node:12-buster-slim
RUN apt update && apt -y install imagemagick && rm -rf rm -rf /var/lib/apt/lists/*
RUN mkdir /usr/src/app
COPY package.json /usr/src/app
WORKDIR /usr/src/app
......
......@@ -3,6 +3,7 @@ const https = require("https");
const fs = require("fs");
const _request = require("request");
const url = require("url");
const gm = require("gm").subClass({ imageMagick: true });
const https_options = {
cert: fs.readFileSync("./certs/fullchain.pem"),
......@@ -76,9 +77,20 @@ function request_avatar(response, username, fallback_username) {
}
} else {
var recv_buf = Buffer.from(body, 'binary');
response.writeHead(200, { "Content-Type": "image/png" });
fs.writeFileSync("./test.png", recv_buf);
response.end(recv_buf);
gm(recv_buf).resize(25, 25).toBuffer("PNG", (error, dst_buf) => {
if (error) {
if (fallback_username) {
request_avatar(response, fallback_username);
} else {
response.writeHead(500);
response.end("Convert error.");
console.error("CONVERT ERROR", error);
}
} else {
response.writeHead(200, { "Content-Type": "image/png" });
response.end(dst_buf);
}
});
}
});
}
......
This diff is collapsed.
......@@ -17,6 +17,7 @@
},
"homepage": "https://github.com/mycard/avatar-helper#readme",
"dependencies": {
"gm": "^1.23.1",
"request": "^2.88.0"
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment