Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to render multi-coloured emojis with ImageMagick?

I have a text that may contain emojis. I want to render it into JPEG image with RMagick (I can also use ImageMagick directly).

I was able to render only monochrome emojis with AndroidEmoji.ttf, but ImageMagick renders interrogation signs if I use AppleColorEmoji.ttf. Here's how I do it:

require 'rmagick'
granite = Magick::ImageList.new('granite:')
canvas = Magick::ImageList.new
canvas.new_image(300, 100, Magick::TextureFill.new(granite))

input = "👠 👯👢 👣"
text = Magick::Draw.new
text.font = 'AppleColorEmoji.ttf'
text.pointsize = 20
text.gravity = Magick::CenterGravity
text.annotate(canvas, 0, 0, 0, 0, input)
canvas.write('result.jpg')

Is it possible to render coloured emojis with ImageMagick or is there another tool that can help?

like image 510
endenis Avatar asked Sep 09 '15 08:09

endenis


1 Answers

You can use pango for text rendering (as of v6.7.6-3):

convert pango:'Hello! 😀How are you?' example.png

Produces this image (using v7.0.8-36)

example.png

See https://www.imagemagick.org/Usage/text/#pango for more details on how to use pango with ImageMagick


I'm on Ubuntu 18.04, using ImageMagick 7.0.8-36 (by compiling from source), which looks to have this configuration

Features: Cipher DPC HDRI OpenMP 
Delegates (built-in): bzlib djvu fontconfig freetype jbig jng jpeg lcms lqr lzma openexr pangocairo png tiff wmf x xml zlib

And it looks like I'm using Pangocairo 1.40.14

$ convert -list format | grep -i pango
    PANGO* r--   Pango Markup Language (Pangocairo 1.40.14)
like image 178
RasmusWL Avatar answered Sep 26 '22 10:09

RasmusWL