![]() ![]() I then centre the trimmed text, using -gravity center and expand the background out (using -extent) so that the text box is always the same size, then I can position it (with -geometry) when compositing it relative to the top-left corner as I reset -gravity to NorthWest. I generate the text with label: to the best automatic size, then trim off any excess space around the text. convert sea.jpg \( -size 173x50 -background none label:"A" -trim -gravity center -extent 173x50 \) -gravity northwest -geometry +312+66 -composite result.pngĪnd this: convert sea.jpg \( -size 173x50 -background none label:"A very much longer label" -trim -gravity center -extent 173x50 \) -gravity northwest -geometry +312+66 -composite result.pngīasically, I am using some "aside processing" in parentheses to generate the text and then compositing it onto the page afterwards. With what I have now gathered, I think this may be your best option. And besides I wouldn't know how to automatically calculate the pointsize (did the above by trial and error). Which is kinda OK, but note the weird text coordinates I have to use to get that. pointsize 65 -gravity center -draw "text 148,-94 'Hello'" test3.jpg Note how the coordinates I specify (the rectangle's center) become the bottom left anchor point for the text! (this surprised me)Īnd if I do: convert test.jpg -font Arial -fill yellow \ pointsize 65 -draw "text 398,90 'Hello'" test2.jpg But I want to specify exact (absolute) coordinates, and that should be the center of the text.įor example, if I do this: convert test.jpg -font Arial -fill yellow \ text coordinates become relative to the entire image's center. How to get the text centered, when I use -gravity center it seems to apply to the position of the text within the entire image, i.e. How to do this 'best fit' feature with ImageMagick (I don't know how to dynamically determine the required -pointsize for this) no word wrapping or multi line), and have it fit exactly in the rectangle, and make sure it's centered (the center of the text is in the center of the rectangle). In either case, independent of how short or long the text is, I would like to print it in one line (i.e. On the other hand with a long (wide) string, the rectangle's width will determine the size: ![]() If it's a very short (narrow) string, the rectangle's height will be the limiting factor: Now I want to render some text with ImageMagick, so that it fits exactly within the rectangle. (for illustratory purposes I put the coordinates of the rectangle and its size and center in there) I have an image like this, with a rectangle at specific coordinates: ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |