Drop shadow on text

后端 未结 2 1963
星月不相逢
星月不相逢 2020-12-30 09:31

I am looking to add drop shadow to text on an image using PHP.

I am aware on how to add text to images and how some libraries allow you to add block shadowing, but I

相关标签:
2条回答
  • 2020-12-30 10:23

    What you want is Imagick::shadowImage ( float $opacity , float $sigma , int $x , int $y )

    Here's an example where I put a drop shadow on some text and then superimpose that on a background image...

    $background_layer = new Imagick('poster_pic_01.jpg'); # background image
    
    $text_layer = new Imagick('transparent400.png'); # empty transparent png of the same size
    $text_layer->annotateImage( $ImagickDraw, $pad_left, $pad_top, 0, "Your text here" );
    
    /* create drop shadow on it's own layer */
    $shadow_layer = $text_layer->clone(); 
    $shadow_layer->setImageBackgroundColor( new ImagickPixel( 'black' ) ); 
    $shadow_layer->shadowImage( 75, 5, 5, 5 ); 
    
    /* composite original text_layer onto shadow_layer */
    $shadow_layer->compositeImage( $text_layer, Imagick::COMPOSITE_OVER, 0, 0 ); 
    
    /* composite shadow_layer (which now has text AND the shadow) onto image_layer */
    $background_layer->compositeImage( $shadow_layer, Imagick::COMPOSITE_OVER, 0, 0 ); 
    

    Hope this helps,

    Roger

    0 讨论(0)
  • 2020-12-30 10:32

    GD can't do this out of the box. If you can, use ImageMagick. Examples on how to do shaped shadows here.

    0 讨论(0)
提交回复
热议问题