龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

图片裁剪 php剪切图片并给图片打上水印的代码

时间:2014-06-28 02:58来源:网络整理 作者:网络 点击:
分享到:
php剪切图片并给图片打上水印的代码 [代码片段(49行)] 此程序可以基于图片进行传入的分辨率对图片进行剪切,同时将生成的内存图片加入回车桌面的logo
$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
精彩图集

赞助商链接