Contain Telegram stickers in a 512x512 box

Fixes https://github.com/turt2live/matrix-dimension/issues/251
This commit is contained in:
Travis Ralston 2019-03-23 19:36:01 -06:00
parent 630a236d7d
commit f894af79b6

View File

@ -81,8 +81,12 @@ export class AdminStickerService {
for (const tgSticker of tgPack.stickers) { for (const tgSticker of tgPack.stickers) {
LogService.info("AdminStickerService", "Importing sticker from " + tgSticker.url); LogService.info("AdminStickerService", "Importing sticker from " + tgSticker.url);
const buffer = await mx.downloadFromUrl(tgSticker.url); const buffer = await mx.downloadFromUrl(tgSticker.url);
console.log(typeof(buffer)); const png = await sharp(buffer).resize({
const png = await sharp(buffer).png().toBuffer(); width: 512,
height: 512,
fit: 'contain',
background: 'rgba(0,0,0,0)',
}).png().toBuffer();
const mxc = await mx.upload(png, "image/png"); const mxc = await mx.upload(png, "image/png");
const serverName = mxc.substring("mxc://".length).split("/")[0]; const serverName = mxc.substring("mxc://".length).split("/")[0];
const contentId = mxc.substring("mxc://".length).split("/")[1]; const contentId = mxc.substring("mxc://".length).split("/")[1];