Drop shadow on text

后端 未结 2 1980
星月不相逢
星月不相逢 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

提交回复
热议问题