Page 1 of 1

Embed images in text

Posted: 2017-01-30T10:13:28-07:00
by green_meep
Hello,

I am using RMagick on Windows to render cards. Apologies if this is not the correct subforum, but I couldn't find one that was for RMagick.

I have to use ImageMagick <7.0 because that is what RMagick supports and I am using the latest version that I could find - I believe 6.9.

I want to embed images in my text. I know that ImageMagick is perfectly capable of compositing two images, but the issue that comes to mind is that the image can be anywhere in the text. I also have to deal with things like text-alignment. I saw that Pango might be a possible option, but I am unsure exactly where to progress there. Even a simple convert command would be helpful.

Thanks!

Re: Embed images in text

Posted: 2017-01-30T10:30:45-07:00
by fmw42
It would help us to know exactly what you are trying to do. Please upload an example image to some place such as dropbox.com and put the URL here. Then explain where you want the image and the text or show an example with an image in the text.

Also please identify your exact IM version and OS/platform. You can get the IM version from

Code: Select all

convert -version

Re: Embed images in text

Posted: 2017-01-30T10:42:28-07:00
by green_meep
Thanks for your response.

My IM version: 6.9.7-3 Q16 x64, on Windows 10.

Essentially, I would like to treat an image as just another character, where it can be anywhere in a block of text and have the text wrapped around it. So, basically an emoticon, really.
Image

Image

Re: Embed images in text

Posted: 2017-01-30T10:47:56-07:00
by fmw42
IM does not have any emoticon or color symbols as a font. So any image and the text on either side needs to be planned out.

You can create three images. The first is a text image create from "I am some text" using the IM function label:"I am some text". The second is your emoticon. The third is your text image create from label:"image". Then you could just append the three images.

See
http://www.imagemagick.org/Usage/text/#label
http://www.imagemagick.org/Usage/layers/#append

Alternately, you can create your text image with a white area where you want the emoticon. Then you can insert the emoticon using -compose over -composite in the proper location.

Re: Embed images in text

Posted: 2017-01-30T10:58:54-07:00
by fmw42
See http://www.imagemagick.org/Usage/text/#mixed_font_lines. Where you would replace one set of text with your emoticon.

Re: Embed images in text

Posted: 2017-01-30T11:03:03-07:00
by fmw42
See also http://www.imagemagick.org/Usage/quantize/#diy_symbols. Though this is not what you want, if you have a black symbol font, you could use Pango to mix fonts and color them as desired.

Re: Embed images in text

Posted: 2017-01-30T11:04:47-07:00
by green_meep
fmw42 wrote: 2017-01-30T10:47:56-07:00 IM does not have any emoticon or color symbols as a font. So any image and the text on either side needs to be planned out.

You can create three images. The first is a text image create from "I am some text" using the IM function label:"I am some text". The second is your emoticon. The third is your text image create from label:"image". Then you could just append the three images.

See
http://www.imagemagick.org/Usage/text/#label
http://www.imagemagick.org/Usage/layers/#append

Alternately, you can create your text image with a white area where you want the emoticon. Then you can insert the emoticon using -compose over -composite in the proper location.
I had been thinking about using the second method, but I was running into problems on where to put the image when the text wasn't left-aligned. I think the first method will work, however.

Thanks for pointing me in the right direction!
fmw42 wrote: 2017-01-30T10:58:54-07:00 See http://www.imagemagick.org/Usage/text/#mixed_font_lines. Where you would replace one set of text with your emoticon.
This link should be helpful. I can always scale the emoticon down to match the size of the font, so hopefully the vertical alignment won't be a problem.

Re: Embed images in text

Posted: 2017-01-30T11:08:47-07:00
by fmw42

Re: Embed images in text

Posted: 2017-01-30T11:13:51-07:00
by fmw42

Re: Embed images in text

Posted: 2017-01-30T12:29:39-07:00
by fmw42
Here is another thought. You could create a text image with all the text you want, but use some symbol of the right size to match the size of your emoticon image. Then you could do a subimage compare using the symbol image as a template. Then you could have a list of emoticons and a script that would replace each occurrence of the matched icon with the next emoticon in your list.