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

时间秒杀一切 提交于 2019-12-01 07:51:48

问题


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?


回答1:


I think you are out of luck... ImageMagick forum.

I suppose you could save all the glyphs as PNG files and append them together to make a "textspeak sentence"

convert smile.png StupidShoeThing.png arnie.png +append txtspeak.png




回答2:


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)

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)


来源:https://stackoverflow.com/questions/32475060/is-it-possible-to-render-multi-coloured-emojis-with-imagemagick

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!