MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / iconMaskedFor

Function iconMaskedFor

eat/eat.ts:136–187  ·  view source on GitHub ↗
(params: {
  role: RoleConfig;
  avatar: Buffer;
})

Source from the content-addressed store, hash-verified

134}
135
136async function iconMaskedFor(params: {
137 role: RoleConfig;
138 avatar: Buffer;
139}): Promise<sharp.OverlayOptions> {
140 const { role, avatar } = params;
141
142 const maskBuffer = await getAssetBuffer(role.mask);
143 const { width: maskWidth, height: maskHeight } = await sharp(
144 maskBuffer
145 ).metadata();
146
147 let iconRotate = await sharp(avatar).resize(maskWidth, maskHeight).toBuffer();
148
149 if (role.rotate) {
150 iconRotate = await sharp(iconRotate).rotate(role.rotate).toBuffer();
151 }
152 if (role.brightness) {
153 iconRotate = await sharp(iconRotate)
154 .modulate({ brightness: role.brightness })
155 .toBuffer();
156 }
157
158 let iconSharp = sharp(iconRotate);
159
160 const { width: iconWidth, height: iconHeight } = await iconSharp.metadata();
161
162 const left = Math.max(0, Math.floor((iconWidth - maskWidth) / 2));
163 const top = Math.max(0, Math.floor((iconHeight - maskHeight) / 2));
164
165 let cropped = iconSharp.extract({
166 left,
167 top,
168 width: maskWidth,
169 height: maskHeight,
170 });
171
172 let iconMasked = await cropped
173 .composite([
174 {
175 input: maskBuffer,
176 blend: "dest-in",
177 },
178 ])
179 .png()
180 .toBuffer();
181
182 return {
183 input: iconMasked,
184 top: role.y,
185 left: role.x,
186 };
187}
188
189async function downloadProfilePhoto(msg: Api.Message): Promise<Buffer | null> {
190 const replied = await safeGetReplyMessage(msg);

Callers 1

compositeWithEntryConfigFunction · 0.85

Calls 1

getAssetBufferFunction · 0.85

Tested by

no test coverage detected