$dir = opendir (dirname(__FILE__))
while (!!$_file = readdir($dir)){
list($filesname,$kzm)=explode(".",$_file)//获取扩展名
if($kzm=="gif" or $kzm=="jpg" or $kzm=="JPG" or $kzm=="png") {
if(!makethumb("$_file","120","120","100")){
echo '执行成功!'
}else{
echo '执行失败!'
}
}
}
closedir($dir)
/**
* 处理缩略图并添加水印函数
* @access publiuc
* @param $srcFile-----------图片文件名
* @param $dstFile-----------另存的文件名
* @param $dstW-------------图片保存的宽度
* @param $dstH--------------图片保存的高度
* @param $rate---------------图片保存的品质
* @param $markwords-----水印文字
* @param $markimage-----水印图片
* @param 使用方法 makethumb("a.jpg","b.jpg","120","120","100")
*/
function makethumb($srcFile/*,$dstFile*/,$dstW,$dstH,$rate=100/*,$markwords=null,$markimage=null*/) {
$data = GetImageSize($srcFile)
switch($data[2]) {
case 1:
$im=@ImageCreateFromGIF($srcFile)
break
case 2:
$im=@ImageCreateFromJPEG($srcFile)
break
case 3:
$im=@ImageCreateFromPNG($srcFile)
break
}
if(!$im) return False
$srcW=ImageSX($im)
$srcH=ImageSY($im)
$dstX=0
$dstY=0
if ($srcW*$dstH>$srcH*$dstW) {
$fdstH = round($srcH*$dstW/$srcW)
$dstY = floor(($dstH-$fdstH)/2)
$fdstW = $dstW
}
else
{
$fdstW = round($srcW*$dstH/$srcH)
$dstX = floor(($dstW-$fdstW)/2)
$fdstH = $dstH
}
$ni=ImageCreateTrueColor($dstW,$dstH)
$dstX=($dstX<0)?0:$dstX
$dstY=($dstX<0)?0:$dstY
$dstX=($dstX>($dstW/2))?floor($dstW/2):$dstX
$dstY=($dstY>($dstH/2))?floor($dstH/s):$dstY
$white = ImageColorAllocate($ni,255,255,255)
$black = ImageColorAllocate($ni,0,0,0)
imagefilledrectangle($ni,0,0,$dstW,$dstH,$white)// 填充背景色
ImageCopyResized($ni,$im,$dstX,$dstY,0,0,$fdstW,$fdstH,$srcW,$srcH)
//if($markwords!=null){
// $markwords=iconv("gb2312","UTF-8",$markwords)
// //转换文字编码
// ImageTTFText($ni,20,30,450,560,$black,"simhei.ttf",$markwords) //写入文字水印,参数依次为,文字大小|偏转度|横坐标|纵坐标|文字颜色|文字类型|文字内容
//}elseif($markimage!=null) {
// $wimage_data = GetImageSize($markimage)
// switch($wimage_data[2]) {
// case 1:
// $wimage=@ImageCreateFromGIF($markimage)
// break
// case 2:
// $wimage=@ImageCreateFromJPEG($markimage)
// break
// case 3:
// $wimage=@ImageCreateFromPNG($markimage)
// break
// }
// imagecopy($ni,$wimage,500,560,0,0,88,31) //写入图片水印,水印图片大小默认为88*31
// imagedestroy($wimage)
//}
$dstFile = $srcFile.'.gif'
ImageJpeg($ni,$dstFile,$rate)
//ImageJpeg($ni,$srcFile,$rate)
imagedestroy($im)
imagedestroy($ni)
}
给全站图片加水印,思路是,找出网站图片目录,循环遍历该目录将里面的图片通过一个加水印函数处理,不明hi我或Q我:573780643以下为代码:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
Public Function AddPersitsJpeg(Path)
'**************加图片水印*******************
Dim photo,logo,photopath,logopath
Set Photo = Server.CreateObject("Persits.Jpeg")
PhotoPath = Server.MapPath(Path) 'Path为路片路径及名称
Photo.Open PhotoPath '打开图片
Set Logo = Server.CreateObject("Persits.Jpeg")
LogoPath = Server.MapPath("logo/sinalogo.gif") '水印图片的路径(自己修改)
Logo.Open LogoPath
Logo.Width = photo.width /4 '水印图片的宽度
Logo.Height = photo.width /12
Photo.Canvas.Pen.Color = &H000000
Photo.Canvas.Pen.Width = 0
Photo.Canvas.Brush.Solid = False
Photo.DrawImage (photo.width-Logo.Width-20), photo.height-Logo.Height-10, Logo,0.6
photo.Save Server.MapPath(Path) ''水印显示在图片上的XY位置
Set logo = Nothing
Set photo = Nothing
End Function
%>
<%
Set fso=Server.CreateObject("Scripting.FileSystemObject")
dim FileName
FPath="pic/"'网站图片目录(自己修改)
Set fs = fso.GetFolder(server.MapPath(FPath))
Set f = fs.Files
For each k in f'循环目录
AddPersitsJpeg(FPath&k.name) '用AddPersitsJpeg函数给图片加水印
next
end if
%>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)