mirror of
https://github.com/turt2live/matrix-dimension.git
synced 2024-09-02 23:21:58 +00:00
feat: Use height and width from downloaded Telegram sticker
This commit is contained in:
parent
9e2393ceca
commit
a768076c03
@ -85,16 +85,18 @@ 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);
|
||||||
const png = await sharp(buffer).resize({
|
const image = await sharp(buffer);
|
||||||
width: 512,
|
const metadata = await image.metadata();
|
||||||
height: 512,
|
const png = await image.resize({
|
||||||
|
width: metadata.width,
|
||||||
|
height: metadata.height,
|
||||||
fit: 'contain',
|
fit: 'contain',
|
||||||
background: 'rgba(0,0,0,0)',
|
background: 'rgba(0,0,0,0)',
|
||||||
}).png().toBuffer();
|
}).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];
|
||||||
const thumbMxc = await mx.uploadFromUrl(await mx.getThumbnailUrl(serverName, contentId, 512, 512, "scale", false), "image/png");
|
const thumbMxc = await mx.uploadFromUrl(await mx.getThumbnailUrl(serverName, contentId, metadata.width, metadata.height, "scale", false), "image/png");
|
||||||
|
|
||||||
stickers.push(await Sticker.create({
|
stickers.push(await Sticker.create({
|
||||||
packId: pack.id,
|
packId: pack.id,
|
||||||
@ -102,8 +104,8 @@ export class AdminStickerService {
|
|||||||
description: tgSticker.emoji,
|
description: tgSticker.emoji,
|
||||||
imageMxc: mxc,
|
imageMxc: mxc,
|
||||||
thumbnailMxc: thumbMxc,
|
thumbnailMxc: thumbMxc,
|
||||||
thumbnailWidth: 512,
|
thumbnailWidth: metadata.width,
|
||||||
thumbnailHeight: 512,
|
thumbnailHeight: metadata.height,
|
||||||
mimetype: "image/png",
|
mimetype: "image/png",
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user