幫客之家(www.Bkjia.com)教程 PHP圖片水印效果的實例代碼
以下為引用的內容:<?php
//$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("06.png","123.png","07.png",370,285,150,15);
?>