3
$\begingroup$

I want to convert a text slogan into graphic, and then add to an image. However, the long text is cropped. How to fix?

Here is the code:

slogan[text1_, text2_] := Block[{s1, s2},
  s1 = Graphics[{Text[
      Style[text1, FontSize -> 30, Bold, Black, Background -> None, 
       FontFamily -> "SeasideResortNF"]]}];
  s2 = Graphics[{Text[
      Style[text2, FontSize -> 25, Bold, Black, Background -> None, 
       FontFamily -> "Alex Brush"]]}];
  ImageCompose[s1, s2, Scaled[{.5, 0.35}]]
  ]

And for the long text input:

slogan["'This long text is cropped'", "Why?"]

Result:

enter image description here

$\endgroup$
2
  • $\begingroup$ windows 10, Mathematica 11.0. $\endgroup$
    – Nam Nguyen
    Feb 2, 2018 at 11:14
  • $\begingroup$ Maybe you don't have the font. But not the problem, can you just try a very long text"? And it is cropped out. $\endgroup$
    – Nam Nguyen
    Feb 2, 2018 at 11:15

1 Answer 1

2
$\begingroup$

The default graphic width of 360 pixels is being exceeded. Find out how big your text is and fit the graphic accordingly, e.g.

slogan[text1_, text2_] := Block[{s1, s2},

  maxwidth = Max[360,
    First@ImageDimensions@Rasterize@
       Text[Style[text1, FontSize -> 30, Bold, Black,
         Background -> None, FontFamily -> "Broadway"]],
    First@ImageDimensions@Rasterize@
       Text[Style[text2, FontSize -> 25, Bold, Black,
         Background -> None, FontFamily -> "Script MT Bold"]]];

  s1 = Graphics[{Text[
      Style[text1, FontSize -> 30, Bold, Black, Background -> None, 
       FontFamily -> "Broadway"]]}, ImageSize -> maxwidth]; 
  s2 = Graphics[{Text[
      Style[text2, FontSize -> 25, Bold, Black, Background -> None, 
       FontFamily -> "Script MT Bold"]]}, ImageSize -> maxwidth]; 
  ImageCompose[s1, s2, Scaled[{.5, 0.35}]]]

slogan["'This long text is cropped'", "Why?"]

enter image description here

$\endgroup$
1
  • $\begingroup$ +1! Exactly! Thank you for your help! Vote up! $\endgroup$
    – Nam Nguyen
    Feb 2, 2018 at 14:09

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.