diff --git a/src/Socket/chats.ts b/src/Socket/chats.ts index bed2f79..856d8cb 100644 --- a/src/Socket/chats.ts +++ b/src/Socket/chats.ts @@ -257,7 +257,11 @@ export const makeChatsSocket = (config: SocketConfig) => { } /** update the profile picture for yourself or a group */ - const updateProfilePicture = async (jid: string, content: WAMediaUpload) => { + const updateProfilePicture = async ( + jid: string, + content: WAMediaUpload, + dimensions?: { width: number; height: number } + ) => { let targetJid if (!jid) { throw new Boom( @@ -269,7 +273,7 @@ export const makeChatsSocket = (config: SocketConfig) => { targetJid = jidNormalizedUser(jid) // in case it is someone other than us } - const { img } = await generateProfilePicture(content) + const { img } = await generateProfilePicture(content, dimensions) await query({ tag: 'iq', attrs: { diff --git a/src/Utils/messages-media.ts b/src/Utils/messages-media.ts index ebfe3a3..6bbf072 100644 --- a/src/Utils/messages-media.ts +++ b/src/Utils/messages-media.ts @@ -139,7 +139,12 @@ export const extractImageThumb = async (bufferOrFilePath: Readable | Buffer | st export const encodeBase64EncodedStringForUpload = (b64: string) => encodeURIComponent(b64.replace(/\+/g, '-').replace(/\//g, '_').replace(/\=+$/, '')) -export const generateProfilePicture = async (mediaUpload: WAMediaUpload) => { +export const generateProfilePicture = async ( + mediaUpload: WAMediaUpload, + dimensions?: { width: number; height: number } +) => { + const { width: w = 640, height: h = 640 } = dimensions || {} + let bufferOrFilePath: Buffer | string if (Buffer.isBuffer(mediaUpload)) { bufferOrFilePath = mediaUpload @@ -154,7 +159,7 @@ export const generateProfilePicture = async (mediaUpload: WAMediaUpload) => { if ('sharp' in lib && typeof lib.sharp?.default === 'function') { img = lib.sharp .default(bufferOrFilePath) - .resize(640, 640) + .resize(w, h) .jpeg({ quality: 50 }) @@ -165,7 +170,7 @@ export const generateProfilePicture = async (mediaUpload: WAMediaUpload) => { const min = Math.min(jimp.getWidth(), jimp.getHeight()) const cropped = jimp.crop(0, 0, min, min) - img = cropped.quality(50).resize(640, 640, RESIZE_BILINEAR).getBufferAsync(MIME_JPEG) + img = cropped.quality(50).resize(w, h, RESIZE_BILINEAR).getBufferAsync(MIME_JPEG) } else { throw new Boom('No image processing library available') }