Viber Stickers for Telegram

This is hack guide on creating Telegram stickers from Viber stickers. It is written for Mac users.

Location of original sticker files on Mac Viber: /Users/username/Library/Application Support/ViberPC/data/stickers/ (make sure to replace “username” with your OS X username). That is parent stickers directory of Viber.

Before anything, it is wise to clean empty sticker directories. Run in Terminal:

find ~/Library/Application\ Support/ViberPC/data/stickers -type d -empty -delete

Use Finder to navigate to parent stickers directory and browse sticker files: Go -> Go to Folder…:

~/Library/Application Support/ViberPC/data/stickers

Sub-directories inside correspond to sticker quality, i.e.:

  • 40 – 88×88
  • 43 – 95×95
  • 60 – 132×132
  • 300 – all dimensions up to 132×132 + SVG (!). We will use SVG stickers since they are most appropriate to convert to Telegram format

To batch convert sticker pack to Telegram format

Need to install on Mac

  • PhantomJS – this is for conversion script to be able to read SVG sticker files
  • SvgExport – this will convert SVG images to PNG format for Telegram
  • ImageMagick – this does the job of trimming PNG file to specified dimensions
  • InkScape – this is additional utility for conerting to PNG, we will use it for some edge cases
  • OptiPng – this will optimize our Telegram stickers to be small in size!

Run this in Terminal to install everything:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install phantomjs
brew install npm
npm install svgexport -g
brew install imagemagick
brew cask install xquartz inkscape # inkscape with dependency

Once it’s all installed, we need to adjust one file.
Open up Terminal app and run nano /usr/local/lib/node_modules/svgexport/render.js and find code with setTimeout, and change it from 0 to 3000.

      setTimeout(function() {
        try {
          page.render(imgfile, {
            format : output.format,
            quality : output.quality
          });
          system.stdout.writeLine(svgfile + ' ' + imgfile + ' '
              + output.toString());
          done && done();
        } catch (e) {
          done && done(e);
        }
      }, 3000);

Just save the file. This change will make sure that last frame (not first frame) of SVG animation is exported.

Converting a single pack

SVG stickers pack to Telegram PNG pack

Navigate in terminal to a directory with SVG stickers (sticker pack).
Then run this script:

mkdir svgexport
for file in ./*.svg
do
  base=${file##*/}
  base=${base%.*}
  if [[ "$base" == *_frame ]]
  then
    continue
  else
    echo "Converting $file"
    svgexport $file ./svgexport/${base}.png pad 9216:9216 # this does not trim, only fits
    mogrify -density 9216 -trim -gravity center -resize 512x512 ./svgexport/${base}.png # trim properly
    optipng -o7 -strip all ./svgexport/${base}.png
  fi
done

Technically, the script renders each SVG within command line browser in a huge viewport (9216x9216), then using ImageMagick to trim and resize the image to fit within 512x512 square.

The script will run for some time: it will wait for SVG animatios to complete and make extensive optimization for Telegram. After it’s done running, you have svgexport directory containing 512 x 512 png stickers for Telegram ready to be uploaded!

Simply move it somewhere out from Viber data directory, then message @stickers bot on Telegram and start uploading your sticker pack.

PNG stickers pack to Telegram PNG pack

If you failed to find SVG stickers in Viber, it’s likely that the stickers you want to convert are PNG only. Navigate in terminal to a directory with PNG stickers (sticker pack). Those will be likely within parent directory 60, where lower quality stickers can be found.
Then run this script:

mkdir pngexport
for file in ./*.png
do
  base=${file##*/}
  base=${base%.*}
  if [[ "$base" == *_frame ]]
  then
    continue
  else
    echo "Converting $file"
    convert $file -trim -resize 512x512 ./pngexport/${base}.png
    optipng -o7 -strip all ./pngexport/${base}.png
  fi
done

The script will run quickly: it will upscale PNG stickers to fit within 512x512 square as required by Telegram. After it’s done running, you have pngexport directory containing 512 x 512 png stickers for Telegram ready to be uploaded!

Simply move it somewhere out from Viber data directory, then message @stickers bot on Telegram and start uploading your sticker pack.

Troubleshooting

Some converted stickers are missing text / image parts

This happens when SVG sticker is bad and we need to use a different tool for those few images that you find broken. Example for sticker file 00003302.svg:

inkscape --export-area-drawing -z -e 00003302.png -h 512 00003302.svg

We are not using this method in the script for batch processing because it will export just the first frame of animation, which is not desirable for all stickers.

Considerations

PNG based Viber packs

There are still some interesting non-SVG stickers, i.e.:
/Users/username/Library/Application Support/ViberPC/data/stickers/40/2000 – Mayo (white cat, English)

You may also like...

Leave a Reply

Your email address will not be published.