糯米文學吧

位置:首頁 > 設計 > 網頁設計

php使用imagick給圖片加水印的方法

PHP是一種HTML內嵌式的語言,PHP與微軟的ASP頗有幾分相似,下面我們來看一篇關於php使用imagick給圖片加水印的`方法吧,希望這篇文章能夠讓各位瞭解到imagick圖片加水印的個方法方式。

php使用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 加水