萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> php編程 >> php圖片上傳並生成水印

php圖片上傳並生成水印

php圖片上傳並生成水印

<?php  
header('Content-Type:text/html;charset=gb2312');
$animation = new Imagick();               
$animation->setFormat( "gif" ); 
$image = new Imagick('/skin/'.$_GET["ys"].'.gif');
$unitl = $image->getNumberImages();     
for ($i=0; $i<$unitl; $i++) {
$image->setImageIndex($i);
    $first = new Imagick($_GET["yh"]);
 $bl = new Imagick("/skin/bl.jpg");
    $thisimage = new Imagick();
    $thisimage->readImageBlob($image);
$srcwh = $thisimage->getImageGeometry();
$bl->thumbnailImage ($srcwh["width"],$srcwh["height"],false);
 if ($_GET["kuan"]==0 and $_GET["gao"]==0)
 {
 $first->thumbnailImage ($srcwh["width"],$srcwh["height"],false);     //這裡false就是拉伸了 true為不拉伸
 }
 else
 {
 $first->thumbnailImage ($_GET["kuan"],$_GET["gao"],false); //這裡false就是拉伸了 true為不拉伸
 }
 $bl->compositeImage($first,Imagick::COMPOSITE_OVER,$_GET["x"],$_GET["y"]);

    $delay = $thisimage->getImageDelay();
    $bl->compositeImage($thisimage,Imagick::COMPOSITE_OVER,0,0);
 $animation->addImage($bl);
    $animation->setImageDelay( $delay ); 
}
$picname=date("ymdhs")."_".mt_rand(10000,99999).".gif";
$name    = "/user/".$picname;
$animation->writeImages($name,1);
echo "<H1></H1>
<DIV class=stborder>
<TABLE cellSpacing=0 cellPadding=0 border=0>
  <TBODY>
  <TR>
    <TD id=picMain align=middle> <img id="qqq" name="qqq" src="/user/{$picname}"><br><iframe   name=demo   style="display:none"></iframe> 
    <a href=#pic onclick="savepic(document.getElementById('qqq'))"><font style="color: #FFFFFF; text-decoration: underline; font-size: 12px;">下載圖片</font></a>  <a href=#pic onclick="copypic(0,'qqq')"><font style="color: #FFFFFF; text-decoration: underline; font-size: 12px;">復制圖片</font></a>
</TD></TR></TBODY></TABLE></DIV>
<DIV class=clear></DIV>";
//header( "Content-Type: image/gif" );
//echo $animation->getImagesBlob();
//echo $animation;
?>

copyright © 萬盛學電腦網 all rights reserved