Page 1 of 1
Positioning image relative to text?
Posted: 2016-09-24T12:31:12-07:00
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
Re: Positioning image relative to text?
Posted: 2016-09-24T13:03:19-07:00
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.
Re: Positioning image relative to text?
Posted: 2016-09-24T18:18:36-07:00
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?
Re: Positioning image relative to text?
Posted: 2016-09-24T18:52:20-07:00
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.
Re: Positioning image relative to text?
Posted: 2016-09-24T23:41:50-07:00
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
Re: Positioning image relative to text?
Posted: 2016-09-25T00:20:19-07:00
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.
Re: Positioning image relative to text?
Posted: 2016-09-25T00:43:17-07:00
by r2997790
GeeMack, you are very kind and generous. Thank you for your fantastic suggestion. I'll give it a go!