2

I want to add an overlay text with text shadow to an image. So far I have been able to achieve this
// top text imagettftext($im, $font_size+2, 0, $text1_params['centered_start'], $font_size+$margin, $black, $font, $text1_params['text'] ); imagettftext($im, $font_size, 0, $text1_params['centered_start'], $font_size+$margin, $white, $font, $text1_params['text'] ); // bottom text imagettftext($im, $font_size, 0, $text2_params['centered_start'] , $image_height-$text2_params['height']+$font_size+$margin, $black, $font, $text2_params['text'] ); imagettftext($im, $font_size, 0, $text2_params['centered_start']-2, $image_height-$text2_params['height']+$font_size+$margin-2, $white, $font, $text2_params['text'] );

This is what the result looks like-

enter image description here But I want it to look like this(Notice the subtle difference in both the text shadows)-

enter image description here

Killswitch
  • 346
  • 2
  • 12
  • which of the images is the "want this" version? shadows to the bottom/right of the text, or shadows all around the word (e.g. not a shadow, just a thick border) – Marc B Jun 27 '14 at 20:36
  • @MarcB- I want to achieve the bottom one. Sorry about the confusion. There were some formatting mistakes – Killswitch Jun 27 '14 at 20:39
  • The bottom one is called stroked text, not shadowed text ;) – JohannesB Jun 27 '14 at 22:57

1 Answers1

3

A hackish way is to render the black text 8 times. First time with an offset to the top left, then top center, then top right, then left, and so on. It may leave an outline that's missing some pixels in a few places but it likely won't be noticeable.

EricP
  • 3,395
  • 3
  • 33
  • 46