分类: 系统运维
2012-07-18 09:05:00
function
watermark($destanition,$source,$location=1,$alaph=50){
//build vanvas
two
$dest=getform($destanition);
$desta=$dest[0];
$image=$dest[1];
$src=getform($source);
$srca=$src[0];
//no
need to build pen
//paint what you
want
$destsize=getimagesize($destanition);
$srcsize=getimagesize($source);
switch($location){
case
1:$x=0;$y=0;break;
case
2:$x=$destsize[0]/3;$y=0;break;
case
3:$x=$destsize[0]*2/3;$y=0;break;
case
4:$x=0;$y=$destsize[1]/3;break;
case
5:$x=$destsize[0]/3;$y=$destsize[1]/3;break;
case
6:$x=$destsize[1]*2/3;$y=$destsize[1]/3;break;
case
7:$x=0;$y=$destsize[1]*2/3;break;
case
8:$x=$destsize[0]/3;$y=$destsize[1]*2/3;break;
case
9:$x=$destsize[0]*2/3;$y=$destsize[1]*2/3;break;
}
imagecopymerge($desta,$srca,$x,$y,0,0,$srcsize[0],$srcsize[1],$alaph);
//inform
browser what you have
painted
header('Content-type:'.array_pop(getimagesize($destination)));
//show
or output it
$image;
//imagedestroy
imagedestroy($desta);
imagedestroy($srca);
}
//assist
function part-------------------------
function
getform($file){
$type=array_pop(getimagesize($file));
switch($type){
case
'image/jpeg':$res[0]=imagecreatefromjpeg($file);$res[1]=imagejpeg($res[0]);break;
case
'image/gif':$res[0]=imagecreatefromgif($file);$res[1]=imagegif($res[0]);break;
case
'image/bmp':$res[0]=imagecreatefromwbmp($file);$res[1]=imagewbmp($res[0]);break;
case
'image/png':$res[0]=imagecreatefrompng($file);$res[1]=imagepng($res[0]);break;
default:break;
}
return
$res;
}
watermark('girl.jpg','src.jpg');
?>
原文地址: