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

时间:2020-09-17 18:17:10 PHP 我要投稿

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

  PHP是一种HTML内嵌式的语言,PHP与微软的ASP颇有几分相似,下面我们来看一篇关于php使用imagick给图片加水印的方法吧,希望这篇文章能够让各位了解到imagick图片加水印的个方法方式。

  <?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);

  $image->compositeImage($watermark, imagick::COMPOSITE_OVER, $x, $y);

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

  echo $image;

  ?>

【php使用imagick给图片加水印的方法】相关文章:

php在新浪云中使用imagick的方法10-04

PHP imagick API中文简介11-19

PHP图片加水印十分简单的代码11-20

php引用函数的使用方法11-12

PHP使用方法之phpize11-15

PHP中使用curl方法介绍11-13

php的obFlush与Flush使用方法11-15

PHP中strtotime函数使用方法11-17

PHP 透明水印生成代码参考11-18