php剪切图片并给图片打上水印的代码
此程序转自www.enterdesk.com回车桌面网络图片处理程序
$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,0,0,$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,$x,$y,0,0,$mwh[0],$mwh[1],$mwh[0],$mwh[1]); imagejpeg($dst_r,null,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,$png,$x,$y,0,0,$mwh[0],$mwh[1],$mwh[0],$mwh[1]); imagejpeg($dst_r,null,100); imagedestroy($dst_r); imagedestroy($png); }
此程序可以基于图片进行传入的分辨率对图片进行剪切,同时将生成的内存图片加入回车桌面的logo