Skip to content

Instantly share code, notes, and snippets.

@Darker935
Created November 26, 2020 12:33
Show Gist options
  • Save Darker935/f5b972a71a48d4a198a606cc97839568 to your computer and use it in GitHub Desktop.
Save Darker935/f5b972a71a48d4a198a606cc97839568 to your computer and use it in GitHub Desktop.
WA-Automate codes
const { decryptMedia } = require('@open-wa/wa-decrypt')
const mime = require('mime-types')
const nrc = require('node-run-cmd')
const fs = require('fs-extra')
const sizeOf = require('image-size')
const buffer = await decryptMedia(message)
const fileName = `temp${from}.${mime.extension(mimetype)}`
fs.writeFile(fileName, buffer, function (err) {})
await nrc.run(`convert ${fileName} ${from}.png`)
var dimensions = await sizeOf(`${from}.png`)
console.log(dimensions)
//await nrc.run('convert '+ from + '.png -resize 64x64\! ' + from + '.png')
if (dimensions.width < dimensions.height) {
let cmd = 'mogrify -bordercolor transparent -border ' + (dimensions.height - dimensions.width) / 2 +' '+ from + '.png'
console.log(cmd)
await nrc.run(cmd)
} else if (dimensions.width > dimensions.height) {
let cmd = 'mogrify -bordercolor transparent -border 0x' + (dimensions.width - dimensions.height) / 2 +' '+ from + '.png'
//this is just to see which command is being executed
console.log(cmd)
await nrc.run(cmd)
} else {
}
const stickerData = await fs.readFile(`${from}.png`, {encoding: 'base64'})
console.log(stickerData.length)
client.sendImageAsSticker(from, `data:image/png;base64,${stickerData.toString('base64')}`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment