<?php
require_once(dirname(__FILE__)."/../inc/common.inc.php");

$thisurl=curPageURL();

$forsiteurl1=urlencode($forsiteurl);

if(!$cutimg){
	showerr("图片有误!!");
}else{
	$cutimg=tempdir($cutimg);
	$NewPic=str_replace($webdb[www_url]."/","",$cutimg);
	$NewPic=ROOT_PATH.$NewPic;
	if(!getimagesize($NewPic)){
		showerr("图片有误!!");
	}
	if($action=="cutimg"){
		include(ROOT_PATH."inc/waterimage.php");
		$scale=100;
		cutimg($NewPic,$NewPic,$x,$y,$rw,$rh,$rw,$rh,$scale);
		if($forsiteurl){
			echo "<META HTTP-EQUIV=REFRESH CONTENT='0;URL=$forsiteurl'>";
			exit;
		}else{	
			echo "<script>
						if(self==top){
							alert('剪切成功');
						}else{
							window.parent.hide_cutimg();
						}				
				 </script>";
					
			exit;
		}
		
	}
	if($action=='rotate'){
		//如果旋转图片
		rotate($NewPic,$rotate);
		exit;
	}
	include(ROOT_PATH."inc/waterimage.php");
	$imgage  = getimagesize($NewPic);
	$src_W = $imgage[0]; //获取原图片宽度
	$src_H = $imgage[1]; //获取原图片高度
	cutimg($NewPic,$NewPic,0,0,$src_W,$src_H ,$src_W,$src_H ,100);
}

require("cutimg.htm");

function curPageURL(){
    $pageURL = 'http';
    if ($_SERVER["HTTPS"] == "on")    {
        $pageURL .= "s";
    }
    $pageURL .= "://";
    if ($_SERVER["SERVER_PORT"] != "80")    {
        $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
    }else{
        $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
    }
    return $pageURL;
}

function rotate($filename,$degrees){
	//创建图像资源，以jpeg格式为例
	$source = imagecreatefromjpeg($filename);
	//使用imagerotate()函数按指定的角度旋转
	$rotate = imagerotate($source, $degrees, 0);
	//旋转后的图片保存
	imagejpeg($rotate,$filename);
}
?>