Positioning image relative to text?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
r2997790
Posts: 8
Joined: 2016-09-24T12:26:44-07:00
Authentication code: 1151

Positioning image relative to text?

Post by r2997790 »

Hi Magick People!

Is it possible to position an image relative to a piece of text? I'm new to IM and have managed to position a line of text exactly but now I would like to add an image at the end of the text.

I don't know where the text will end, in terms of pixel position, and would like to position the image adjacent to it, relative to the position of the text, eg. X pixels to the right of the end of the text.

Is this possible?

Many thanks in advance IM ninjas!
R
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Positioning image relative to text?

Post by snibgo »

How do you create the text? You could create it as an image. Then you know the dimensions, and can composite it wherever you want, and you know where the right and bottom edges will be.
snibgo's IM pages: im.snibgo.com
r2997790
Posts: 8
Joined: 2016-09-24T12:26:44-07:00
Authentication code: 1151

Re: Positioning image relative to text?

Post by r2997790 »

Thanks for the reply. I dont know the width of the image as this will be a script running thru several lines so different text/image blocks will have different lengths.

Is there actually a way to find out the width of an image and position another image relative to each other?
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Positioning image relative to text?

Post by GeeMack »

r2997790 wrote:Is there actually a way to find out the width of an image and position another image relative to each other?
There are a few ways to approach this. If you let us know what platform you're working on and which version of ImageMagick you're using we can point you in the right direction. If you have any example before/after type images that would be helpful, too.
r2997790
Posts: 8
Joined: 2016-09-24T12:26:44-07:00
Authentication code: 1151

Re: Positioning image relative to text?

Post by r2997790 »

Thank you. I am using a Windows PC running Windows 10 using the latest version of IM. (Later I'm hoping to put it on a webserver and run it automatically).

The task I'm trying to acheive is to place an emoji at the end of a username and there will be a series of usernames eg.

Scott *smiley face*
Samantha *sad face*
Jo *laughing*

The names are read from a data file. I don't know how long they will be.

I'd like to place the emoji image 10px to the right of the name text. The emoji will be a fixed known size. The text (name) will vary.

Thanks for your help!
R
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Positioning image relative to text?

Post by GeeMack »

r2997790 wrote:I'd like to place the emoji image 10px to the right of the name text. The emoji will be a fixed known size. The text (name) will vary.
One approach would be to make your usernames as labels, essentially separate images, and "+append" your emojis to each username. Then "-append" all the labels to create a single output image. An example from a Windows 10 command line using ImageMagick 7 might look something like this...

Code: Select all

magick -bordercolor none -background none -pointsize 24 ^
   ( label:"Scott" smilyface.png -border 5x5 +append ) ^
   ( label:"Samantha" sadface.png -border 5x5 +append ) ^
   ( label:"Jo" laughing.png -border 5x5 +append ) ^
   -append output.png
Rather than simply output a final image there, you could continue the command to composite the username/emoji combinations wherever you like on some other background.
r2997790
Posts: 8
Joined: 2016-09-24T12:26:44-07:00
Authentication code: 1151

Re: Positioning image relative to text?

Post by r2997790 »

GeeMack, you are very kind and generous. Thank you for your fantastic suggestion. I'll give it a go!
Post Reply