首页 > 开发 > PHP > 正文

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

2024-05-04 21:50:03
字体:
来源:转载
供稿:网友
  1. <?php 
  2. $image = new Imagick(); 
  3. $image->readImage("original.jpg"); 
  4.  
  5. $watermark = new Imagick(); 
  6. $watermark->readImage("/data/mark.png"); 
  7.  
  8. // how big are the images? 
  9. $iWidth = $image->getImageWidth(); 
  10. $iHeight = $image->getImageHeight(); 
  11. $wWidth = $watermark->getImageWidth(); 
  12. $wHeight = $watermark->getImageHeight(); 
  13.  
  14. if ($iHeight < $wHeight || $iWidth < $wWidth) { 
  15.     // resize the watermark 
  16.     $watermark->scaleImage($iWidth$iHeight); 
  17.  
  18.     // get new size 
  19.     $wWidth = $watermark->getImageWidth(); 
  20.     $wHeight = $watermark->getImageHeight(); 
  21.  
  22. // calculate the position 
  23. $x = ($iWidth – $wWidth); 
  24. $y = ($iHeight – $wHeight); 
  25. //Vevb.com 
  26. $image->compositeImage($watermark, imagick::COMPOSITE_OVER, $x$y); 
  27.  
  28. header("Content-Type: image/" . $image->getImageFormat()); 
  29. echo $image
  30. ?> 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表