PHP剪切图片并给图片打上水印的代码
/**
* PHP剪切图片并给图片打上水印的代码
*
* @param
* @arrange 网: jb51.cc
**/
$wh=getimagesize($filename);
$w=$wh[0];
$h=$wh[1];
$fenbianlv=$_REQUEST['tfbl'];
if(preg_match("~(\d+)x(\d+)~",$fenbianlv,$wd)){
$targ_w=intval($wd[1]);
$targ_h=intval($wd[2]);
}
$jpeg_quality = 100;
$img_r = imagecreatefromjpeg($filename);
$dst_r = ImageCreateTrueColor( $targ_w,$targ_h );
$x=($w-$targ_w)/2;
$y=($h-$targ_h)/2;
//ob_clean();
header('Content-type: image/jpeg');
imagecopy($dst_r,$img_r,$x,$y,$targ_w,$targ_h);
imagedestroy($img_r);
$PHPcms_auth = param::get_cookie('auth');
if($PHPcms_auth) {
$auth_key = md5(pc_base::load_config('system','auth_key').$_SERVER['HTTP_USER_AGENT']);
list($userid,$password) = explode("\t",sys_auth($PHPcms_auth,'DECODE',$auth_key));
//echo $userid;
if($userid >0) {
imagejpeg($dst_r,null,$jpeg_quality);
}else{
$png=ImageCreateFromPNG(PHPCMS_PATH.'images/logo.png');
$mwh=getimagesize(PHPCMS_PATH.'images/logo.png');
$x=$targ_w-$mwh[0]-30;
$y=$targ_h-$mwh[1]-30;
imagecopyresampled($dst_r,$png,$mwh[0],$mwh[1],$mwh[1]);
imagejpeg($dst_r,100);
imagedestroy($dst_r);
imagedestroy($png);
}
}else{
$png=ImageCreateFromPNG(PHPCMS_PATH.'images/logo.png');
$mwh=getimagesize(PHPCMS_PATH.'images/logo.png');
$x=$targ_w-$mwh[0]-30;
$y=$targ_h-$mwh[1]-30;
imagecopyresampled($dst_r,100);
imagedestroy($dst_r);
imagedestroy($png);
}
/*** 来自编程之家 jb51.cc(jb51.cc) ***/
此程序可以基于图片进行传入的分辨率对图片进行剪切,同时将生成的内存图片加入回车桌面的logo