I have an image for example:

img = Import[

I'm creating a text graphics object:

string = "a test string";
gObj = Graphics[
   Text[Style[string, FontSize -> 14, FontFamily -> "Arial", Bold, 
     White, Background -> Black]]];

and add it to the image in the left bottom corner:

picFinal = ImageCompose[img, gObj, {60, 10}]

Now when I use a longer string:

string = "a test string that is a bit longer ";

this results in the string not fitting. But I need to add strings with variable sizes to the left bottom corner as well. How can I adapt the position of my string such that it always has a specified distance from the left bottom corner and adapt dynamically to the size of the string?


1 Answer 1


I think the problem here is the automatic rasterisation of the text. When you give a Graphics object to an image based function, it automatically converts it to an image.

   Graphics[Text@"a test string", Background -> LightGray], 
   Graphics[Text@"a test string that is a bit longer", Background -> LightGreen]


Which is fine, but with the big border you lose control of where the text starts. However if you explicitly Rasterize the text, without making it into Graphics, it's more compact and predictable:

gObj = Rasterize[
  Text[Style[string, FontSize -> 14, FontFamily -> "Arial", Bold, 
    White, Background -> Black]], Background -> None]


Then you can use ImageCompose parameters to good effect to always get it in the left bottom:

ImageCompose[img, gObj, {5, 0}, {Left, Bottom}]


  • $\begingroup$ I see, thank you! $\endgroup$
    – holistic
    Oct 25, 2016 at 10:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.