Home > php教程 > php手册 > 一个简单实用的php加图片水印函数

一个简单实用的php加图片水印函数

WBOY
Release: 2016-06-21 08:57:40
Original
819 people have browsed it

以下是引用片段:
以下为引用的内容:
  
 //$backFile:  背景图
 //$copyFile:  待拷贝的图 
 //$resultFile:  生成文件保存地址
 //$copyToX:  拷贝到背景图上的X坐标
 //$copyToY:  拷贝到背景图上的Y坐标
 //$copyToWidth: 把待拷贝的图变为多宽
 //$copyToHeight: 把待拷贝的图变为多高
 function ImgMerge($backFile,$copyFile,$resultFile,$copyToX,$copyToY,$copyToWidth,$copyToHeight)
 {
  //如果文件名后缀不是"PNG"则返回""
  if (GetFileUpperExt($backFile) != "PNG")
   return "";
  //如果文件名后缀不是"PNG"则返回""
  if (GetFileUpperExt($copyFile) != "PNG")
   return "";
  $backImg = ImageCreateFromPng($backFile);
  //如果值没有设置,则返回""
  if (!isset($backImg ))
  {
   return "";
  }
  $backImgX = ImageSX($backImg);
  $backImgY = ImageSX($backImg);
  
  $copyImg = ImageCreateFromPng($copyFile);
  //如果值没有设置,则返回""
  if (!isset($copyImg ))
  {
   return "";
  }
  $copyResizeImg = ImageResize($copyImg, $copyToWidth, $copyToHeight);
  
  $bCopy = ImageCopy($backImg,$copyResizeImg,$copyToX,$copyToY,0,0,$copyToWidth,$copyToHeight);
  if (!$bCopy )
  {
   return "";
  }
  ImageAlphaBlending($backImg, true);
  ImageSaveAlpha($backImg, true);
  
  if (!ImagePng($backImg,$resultFile))
   return "";
  return $resultFile;
 }
 
 //获得传入文件的文件名
 function GetFileUpperExt($fullFile)
 {
  if (!File_Exists($fullFile)) 
   return "";
  $pathInfo = PathInfo($fullFile );  
  return StrToUpper($pathInfo[’extension’]);  
 }
 
 function ImageResize($rImage, $iWidth, $iHeight) 
 {
  $iCanvas = ImageCreate($iWidth, $iHeight);
  $iWidthX  = ImageSX($rImage);
  $iHeightY = ImageSY($rImage);
  ImageCopyResampled($iCanvas, $rImage, 0, 0, 0, 0, $iWidth, $iHeight, $iWidthX, $iHeightY);
  return $iCanvas;
 }
 
 ImgMerge("backImg.png","copyImg.png","imgMerge.png",3,3,30,30);
?> 



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template