当前位置:编程问答 > php >

用imagick组件增加图片水印和php 文字水印,缩略图

php+imagick图片水印

<?php

$first = new Imagick('big.jpg');
$second = new Imagick('logo.png');
//$second->setImageOpacity (0.4);//设置透明度
$dw = new ImagickDraw();
$dw->setGravity(Imagick::GRAVITY_CENTER);//设置位置
$dw->composite($second->getImageCompose(),0,0,50,0,$second);
$first->drawImage($dw);

$first->writeImage('result.jpg');
header('content-type: image/jpg');
echo $first;
?>

imagick+php文字水印

<?php
$canvas = new Imagick('1.jpg');

$draw = new ImagickDraw();
$draw->setFontSize(20);//设置字体大小
$draw->setTextUnderColor(new ImagickPixel ('red'));//设置背景色
$draw->setFillColor (new ImagickPixel('yellow'));//设置字体颜色
$draw->setGravity(Imagick::GRAVITY_SOUTHEAST);//设置水印位置
$draw->setFillAlpha(0.5);
$draw->annotation(0, 0, "9ye.com");

$canvas->drawImage($draw);
$canvas->writeImage('1.fill.jpg');
header("Content-Type: image/jpg");
echo $canvas;
?>

imagick实现缩略图

<?php
$image = new Imagick("a.bmp");
//$image->thumbnailImage (500,500,false); // 变形
$image->thumbnailImage (500,500,true); // 不变形
//$image->cropThumbnailImage (500,500);//压缩后裁剪

$image->writeImage("as.bmp");
header('content-type:image/bmp');
echo $image;
?>

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,