php图片添加水印例子
2016-08-12来源:

图片添加水印我相信各位朋友都知道的,今天我们来看一段php的图片添加水印例子,希望文章能够帮助到各位朋友。

<?php 

  /** 

   * 图片添加水印 

   * $target 源文件路径 

   * $wtrmrk_file 水印图片路径 

   * $newcopy 添加水印后的图片路径 

   * 

   */

  public function watermark_image($target, $wtrmrk_file, $newcopy) { 

    $watermark = imagecreatefrompng($wtrmrk_file); 

    imagealphablending($watermark, false); 

    imagesavealpha($watermark, true); 

    $img = imagecreatefromjpeg($target); 

    $img_w = imagesx($img); 

    $img_h = imagesy($img); 

    $wtrmrk_w = imagesx($watermark); 

    $wtrmrk_h = imagesy($watermark); 

    $dst_x = ($img_w ) – ($wtrmrk_w); // For centering the watermark on any image //phpfensi.com 

    $dst_y = ($img_h) – ($wtrmrk_h ); // For centering the watermark on any image 

    imagecopy($img, $watermark, $dst_x, $dst_y, 0, 0, $wtrmrk_w, $wtrmrk_h); 

    imagejpeg($img, $newcopy, 100); 

    imagedestroy($img); 

    imagedestroy($watermark); 

    //return $img; 

  } 

?>

以上就是本文的全部内容,希望对大家的学习有所帮助

2025公考·省考培训课程试听预约报名

  • 报班类型
  • 姓名
  • 手机号
  • 验证码
推荐信息
Baidu
map