轻风易扬

如果不能在混乱中创造出秩序,那么设计也就失去了意义,我愿去寻找这种秩序感

© 轻风易扬
Powered by LOFTER

轻风易扬之后台技术学习(5)--背景透明的imagick图片水印

/**

 * 给图片加上水印

 *

 * @param $srcImage 地址(不能用网络地址)

 * @param offset   

 *          tb  => 水印的上下间距,

 *          rl  => 水印的左右间距,

 *          set => 水印位置(可选:GRAVITY_NORTHWEST,GRAVITY_NORTH,GRAVITY_EASNORTHT,

 *                               GRAVITY_WEST,GRAVITY_CENTER,GRAVITY_EAST,GRAVITY_SOUTHWEST,

 *                               GRAVITY_SOUTH,:GRAVITY_SOUTHEAST)

 *          waterImg => 水印图片地址(不传则用默认水印)

 * @example

 *  $images = new Images_Handle();

 *  $offset = array('tb'=>10,'rl'=>10,'set'=>Imagick::GRAVITY_SOUTHEAST);

 *  $images->DrawImg($path1,$offset);

 */

function DrawImg($srcImage,$offset){

 

    if(!isset($offset['waterImg'])){

        $offset['waterImg'] = ini_get('yaf.library').'Images/waterImg.png';

    }

 

    $image  = new Imagick($srcImage);

    $water  = new Imagick($offset['waterImg']);

 

    /* 水印设置 */

    $water->setImageFormat("png");

    $water->thumbnailImage( 200, null );

    $shadow = $water->clone();

    $shadow->setImageBackgroundColor( new ImagickPixel( 'black' ) );

    $shadow->shadowImage( 80, 3, 5, 5 );

    $shadow->compositeImage( $water, Imagick::COMPOSITE_OVER, 0, 0 );

    $water = $shadow;

 

    /* 合并 */

    $canvas = new ImagickDraw(); 

    $canvas->color(0,0,imagick::PAINT_FLOODFILL);  

    $canvas->setGravity(Imagick::GRAVITY_SOUTHEAST);//设置位置

    $canvas->composite($water->getImageCompose(),$offset['rl'],$offset['tb'],0,0,$water);

 

    $image->drawImage($canvas);

    $image->writeImage($srcImage);

    //header( "Content-Type: image/{$image->getImageFormat()}" );  

    //echo $image;

来源:小菜敲键盘

评论
热度 ( 2 )
  1. 轻风易扬愤怒的小菜 转载了此文字
TOP