Page 1 of 1

append label with different position

Posted: 2016-06-27T04:38:57-07:00
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.

Re: append label with different position

Posted: 2016-06-27T04:55:28-07:00
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

Re: append label with different position

Posted: 2016-06-27T05:03:01-07:00
by rotem
Great, thank you!

Re: append label with different position

Posted: 2016-06-27T05:40:23-07:00
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?

Re: append label with different position

Posted: 2016-06-27T06:27:57-07:00
by snibgo
Perhaps you need to write a script.

Re: append label with different position

Posted: 2016-06-27T06:40:47-07:00
by rotem
Ok, that is possible, but how can I know what is the width of each char?

Re: append label with different position

Posted: 2016-06-27T06:42:56-07:00
by snibgo
See my first example.

Re: append label with different position

Posted: 2016-06-27T09:07:03-07:00
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

Re: append label with different position

Posted: 2016-06-27T09:22:25-07:00
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

Re: append label with different position

Posted: 2016-06-27T14:53:55-07:00
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

Re: append label with different position

Posted: 2016-06-27T16:17:26-07:00
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.

Re: append label with different position

Posted: 2016-06-27T17:25:30-07:00
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.

Re: append label with different position

Posted: 2016-06-28T01:01:00-07:00
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?

Re: append label with different position

Posted: 2016-06-28T08:43:46-07:00
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