append label with different position

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
rotem
Posts: 46
Joined: 2016-04-15T13:34:32-07:00
Authentication code: 1151

append label with different position

Post by rotem »

Hello,

I'm trying to append several chars together to create a word but with different x/y position for each char.

This is what I'm using

Code: Select all

convert -background none -font ./assets/impact.ttf -pointsize 72 label:"R" label:"O" label:"T" label:"E" label:"M" +append -trim result.png
and this is the result Image

Any help would be appreciate.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: append label with different position

Post by snibgo »

"label:" doesn't allow for positioning within the created image. "+append" just attaches side-by-side.

You could use "-annotate".

Or "label:", but with "-composite" or "-layers", eg:

Code: Select all

convert -background none -pointsize 72 label:R ( label:A -set page +20+30 ) +write info: -layers merge x.png
snibgo's IM pages: im.snibgo.com
rotem
Posts: 46
Joined: 2016-04-15T13:34:32-07:00
Authentication code: 1151

Re: append label with different position

Post by rotem »

Great, thank you!
rotem
Posts: 46
Joined: 2016-04-15T13:34:32-07:00
Authentication code: 1151

Re: append label with different position

Post by rotem »

After going over it more thoroughly I can't use this method since I don't know how much width each char take.

What I'm looking for is the functionality of append but with an option to place a specific char in a different position.

Any idea?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: append label with different position

Post by snibgo »

Perhaps you need to write a script.
snibgo's IM pages: im.snibgo.com
rotem
Posts: 46
Joined: 2016-04-15T13:34:32-07:00
Authentication code: 1151

Re: append label with different position

Post by rotem »

Ok, that is possible, but how can I know what is the width of each char?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: append label with different position

Post by snibgo »

See my first example.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: append label with different position

Post by fmw42 »

I often use label: just to get the image size desired. The rewrite with -annotate. You can also get font metrics with label: or annotate or draw using -debug annotate. See http://www.imagemagick.org/Usage/text/#font_info
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: append label with different position

Post by Bonzo »

I did it once by creating an image of each letter and then joined them together with append.

Image

The problem with this is all the images are on the same size background
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: append label with different position

Post by fmw42 »

If you want to change the spacing, just add -splice after each -trim to add a slight amount of background color to one side or the other. Or use -border to add half to each left/right side and not the top.

See
http://www.imagemagick.org/Usage/crop/#border
http://www.imagemagick.org/Usage/crop/#splice
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: append label with different position

Post by fmw42 »

You can use snibgo's method to get the character size from the trimmed image and then adjust it. You would have to script a loop over each image after trimming to get the dimensions and offsets and then modify it with -set page. Then use -layers merge to combine them.

Actually you can loop over each character and just get the page geometry using string format %@. Then when actually creating the letter images in snibgo's command use -set page based upon the dimensions and offsets from the string format.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: append label with different position

Post by fmw42 »

Actually, I don't think you need to know anything about the character size. You can just use -set page +X+Y to adjust the trimmed images to offset them as desired, one character at a time.
rotem
Posts: 46
Joined: 2016-04-15T13:34:32-07:00
Authentication code: 1151

Re: append label with different position

Post by rotem »

fmw42 wrote:Actually, I don't think you need to know anything about the character size. You can just use -set page +X+Y to adjust the trimmed images to offset them as desired, one character at a time.
That is what I want to do but I need to know in advanced what will be each character size, right?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: append label with different position

Post by fmw42 »

Why do you need the size, if all you want to do is put space between them. But if you need to adjust vertically, then you probably do need the size. You can get that by making a pass over each letter without creating it by using the string format "%@" and storing the size and offsets in an array. Then read the array when actually creating the letters and adjust the offsets as needed. See my post above and http://www.imagemagick.org/script/escape.php
Post Reply