加入收藏 | 设为首页 | 会员中心 | 我要投稿 PHP编程网 - 黄冈站长网 (http://www.0713zz.com/)- 数据应用、建站、人体识别、智能机器人、语音技术!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php使用imagick给图片加水印的办法

发布时间:2022-02-24 11:47:22 所属栏目:PHP教程 来源:互联网
导读:?php $image = new Imagick(); $image-readImage(original.jpg); $watermark = new Imagick(); $watermark-readImage(/data/mark.png); // how big are the images? $iWidth = $image-getImageWidth(); $iHeight = $image-getImageHeight(); $wWidth = $wa
  <?php
  $image = new Imagick();
  $image->readImage("original.jpg");
  
  $watermark = new Imagick();
  $watermark->readImage("/data/mark.png");
  
  // how big are the images?
  $iWidth = $image->getImageWidth();
  $iHeight = $image->getImageHeight();
  $wWidth = $watermark->getImageWidth();
  $wHeight = $watermark->getImageHeight();
  
  if ($iHeight < $wHeight || $iWidth < $wWidth) {
      // resize the watermark
      $watermark->scaleImage($iWidth, $iHeight);
  
      // get new size
      $wWidth = $watermark->getImageWidth();
      $wHeight = $watermark->getImageHeight();
  }
  
  // calculate the position
  $x = ($iWidth – $wWidth);
  $y = ($iHeight – $wHeight);
  //Cuoxin.com
  $image->compositeImage($watermark, imagick::COMPOSITE_OVER, $x, $y);
  
  header("Content-Type: image/" . $image->getImageFormat());
  echo $image;
  ?>
 

(编辑:PHP编程网 - 黄冈站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读