<?php
//获取水印图片
$logo = new Imagick("logo.png");
$logo->setImageResolution(0.01,0.03);
//创建一个Imagick对象,同时获取要处理的源图
$im = new Imagick( "old_large_img_2.jpg" );
//获取源图片宽和高
$srcWH = $im->getImageGeometry();
//图片等比例缩放宽和高设置
if($srcWH['width']>710){
$srcW['width'] = 710;
$srcH['height'] = $srcW['width']/$srcWH['width']*$srcWH['height'];
}else{
$srcW['width'] = $srcWH['width'];
$srcH['height'] = $srcWH['height'];
}
//按照比例进行缩放
$im->thumbnailImage( $srcW['width'], $srcH['height'], true );
// 按照缩略图大小创建一个有颜色的图片
$canvas = new Imagick();
$canvas->newImage( $srcW['width'], $srcH['height'], 'black', 'jpg' ); //pink,black
//添加水印
$im->compositeImage($logo,Imagick::COMPOSITE_OVER,$srcW['width']-280,$srcH['height']-77);
$canvas->setcompressionquality(91);
//合并图片
$canvas->compositeImage( $im, imagick::COMPOSITE_OVER, 0, 0);
//输出图片
header( "Content-Type: image/jpg" );
echo $canvas;
//生成图片
$canvas->writeImage( "test_img/old_large_img_2_96.jpg" );
?>
您可能感兴趣的文章: