下载组件phpimageeditor;
$ vim phpimageeditor/lite/shared/classes/phpimageeditor.php
覆盖
<?php
class PHPImageEditor {
var $srcEdit = "";
var $name = "";
var $srcOriginal = "";
var $srcPng = "";
var $srcWorkWith = "";
var $urlWorkWith = "";
var $resourceWorkWith = false;
var $mimeType = "";
var $actionSaveAndClose = "save";
var $actionRotateLeft = "rotate:90";
var $actionRotateRight = "rotate:-90";
var $actionGrayscale = "grayscale";
var $actionContrast = "contrast";
var $actionBrightness = "brightness";
var $actionUndo = "undo";
var $actionUpdate = "update";
var $actionRotateIsSelected = false;
var $actionRotate = "";
var $actionSeparatorSign = "#";
var $fieldNameKeepProportions = "keepproportions";
var $errorMessages = array();
var $formName = "phpimageeditor";
var $inputWidth = -1;
var $inputHeight = -1;
var $inputCropLeft = 0;
var $inputCropRight = 0;
var $inputCropTop = 0;
var $inputCropBottom = 0;
var $inputKeepProportions = true;
var $inputCropKeepProportions = false;
var $inputCropKeepProportionsRatio = 1;
var $inputPanel = PIE_START_PANEL;
var $inputLanguage = PIE_DEFAULT_LANGUAGE;
var $inputContrast = 0;
var $inputBrightness = 0;
var $inputContrastLast = 0;
var $inputBrightnessLast = 0;
var $inputGrayscale = false;
var $httpImageKey = "imagesrc";
var $texts = array();
var $actions = "";
var $isPostBack = false;
var $isAjaxPost = false;
var $finalWidth = -1;
var $finalHeight = -1;
var $widthKeepProportions = -1;
var $heightKeepProportions = -1;
var $userId = "";
var $fonts = array();
var $doSave = false;
var $contrastMax = 100;
var $brightnessMax = 255;
// var $photoInfo = array();
function PHPImageEditor() {
$this->LoadLanguage();
if (version_compare(phpversion(), PIE_PHP_VERSION_MINIMUM, "<")) {
$this->errorMessages[] = phpversion() . " " . $this->texts["OLD PHP VERSION"] . " " . PIE_PHP_VERSION_MINIMUM;
return;
}
$this->isPostBack = isset($_POST["actiontype"]);
$srcEdit = "";
if ($_GET[$this->httpImageKey] != NULL) {
$l = DIRECTORY_SEPARATOR;
$file = dirname(dirname(dirname(dirname(__FILE__)))) . "{$l}tmp{$l}{$_GET[$this->httpImageKey]}";
#$srcEdit = strip_tags($_GET[$this->httpImageKey]);
$srcEdit = strip_tags($file);
}
if ($srcEdit == "") {
$this->errorMessages[] = $this->texts["NO PROVIDED IMAGE"];
return;
}
$this->srcEdit = urldecode($srcEdit);
if (isset($_POST["userid"]))
$this->userId = $_POST["userid"];
else {
$this->userId = "_" . str_replace(".", "_", $_SERVER['REMOTE_ADDR']);
#In my Virtual box in Windows Vista I'll get :: as ip.
#Remove it to avoid errors.
$this->userId = str_replace("_::", "", $this->userId);
}
$this->SetSrcOriginal();
$this->SetSrcPng();
$this->SetSrcWorkWith();
if (!file_exists($this->srcEdit)) {
$this->errorMessages[] = $this->texts["IMAGE DOES NOT EXIST"];
return;
}
$info = getimagesize($this->srcEdit);
if (!$info) {
$this->errorMessages[] = $this->texts["INVALID IMAGE TYPE"];
return;
}
$this->mimeType = image_type_to_mime_type($info[2]);
// echo image_type_to_mime_type($info[2])."===".image_type_to_mime_type(IMAGETYPE_JPEG);exit;
if ($this->mimeType == image_type_to_mime_type(IMAGETYPE_JPEG) || $this->mimeType == image_type_to_mime_type(IMAGETYPE_GIF) || $this->mimeType == image_type_to_mime_type(IMAGETYPE_PNG)) {
if (!$this->isPostBack)
$this->SaveOriginal();
$this->resourceWorkWith = $this->CreateImage($this->srcOriginal);
$this->SavePng();
copy($this->srcPng, $this->srcWorkWith);
$this->resourceWorkWith = $this->CreateImage($this->srcPng);
}
else {
$this->errorMessages[] = $this->texts["INVALID IMAGE TYPE"];
return;
}
$this->finalWidth = $this->GetWidth();
$this->finalHeight = $this->GetHeight();
$this->widthKeepProportions = $this->GetWidth();
$this->heightKeepProportions = $this->GetHeight();
// $this->photoInfo = $this->GetUserData();
if ($this->isPostBack) {
$this->actionRotateIsSelected = (strip_tags($_POST["rotate"]) != "-1");
$this->actionRotate = strip_tags($_POST["rotate"]);
$this->actions = strip_tags($_POST["actions"]);
$this->isAjaxPost = (strip_tags($_POST["isajaxpost"]) == "true");
$this->inputWidth = (int) strip_tags($_POST["width"]);
$this->inputHeight = (int) strip_tags($_POST["height"]);
$this->inputCropLeft = (int) strip_tags($_POST["cropleft"]);
$this->inputCropRight = (int) strip_tags($_POST["cropright"]);
$this->inputCropTop = (int) strip_tags($_POST["croptop"]);
$this->inputCropBottom = (int) strip_tags($_POST["cropbottom"]);
$this->inputPanel = (int) strip_tags($_POST["panel"]);
$this->inputLanguage = strip_tags($_POST["language"]);
$this->inputKeepProportions = (strip_tags($_POST["keepproportionsval"]) == "1");
$this->inputCropKeepProportions = (strip_tags($_POST["cropkeepproportionsval"]) == "1");
$this->inputCropKeepProportionsRatio = (float) strip_tags($_POST["cropkeepproportionsratio"]);
$this->inputGrayscale = (strip_tags($_POST["grayscaleval"]) == "1");
$this->inputBrightness = (int) strip_tags($_POST["brightness"]);
$this->inputContrast = (int) strip_tags($_POST["contrast"]);
$this->inputBrightnessLast = (int) strip_tags($_POST["brightnesslast"]);
$this->inputContrastLast = (int) strip_tags($_POST["contrastlast"]);
$this->Action(strip_tags($_POST["actiontype"]));
}
}
function LoadLanguage() {
$language = "";
if (isset($_POST["language"])) {
$this->inputLanguage = $_POST["language"];
$language = $this->inputLanguage;
} else if (isset($_GET["language"])) {
$this->inputLanguage = $_GET["language"];
$language = $this->inputLanguage;
} else
$language = PIE_DEFAULT_LANGUAGE;
$tryLanguage = "language/" . $language . ".ini";
if (file_exists($tryLanguage))
$this->texts = PIE_GetTexts("language/" . $language . ".ini");
else
$this->texts = PIE_GetTexts("language/" . PIE_DEFAULT_LANGUAGE . ".ini");
//Load the texts that not exists in the current langugare from english.
$texts = PIE_GetTexts("language/en-GB.ini");
foreach ($texts as $key => $text) {
if (array_key_exists($key, $this->texts) === false)
$this->texts[$key] = $text;
}
}
function SetSrcOriginal() {
$arr = explode("/", $this->srcEdit);
$this->srcOriginal = PIE_IMAGE_ORIGINAL_PATH . $this->AddUserIdToImageSrc($arr[count($arr) - 1]);
}
function SetSrcWorkWith() {
$arr = explode("/", $this->srcEdit);
$srcWorkWith = PIE_IMAGE_WORK_WITH_PATH . $this->AddUserIdToImageSrc($arr[count($arr) - 1]);
$srcWorkWith = substr($srcWorkWith, 0, strripos($srcWorkWith, ".")) . ".png";
$this->srcWorkWith = $srcWorkWith;
// $this->urlWorkWith = $this->isAjaxPost && $_POST['actiontype'] == $this->actionSaveAndClose
// ? "http://".str_replace(DIRECTORY_SEPARATOR,"/",str_replace(DOC_ROOT,$_SERVER['SERVER_NAME'],$this->srcEdit))
// : "http://".str_replace(DIRECTORY_SEPARATOR,"/",str_replace(DOC_ROOT,$_SERVER['SERVER_NAME'],$srcWorkWith))
// ;
if ($_POST['actiontype'] == $this->actionSaveAndClose) {
$this->urlWorkWith = "http://" . str_replace(DIRECTORY_SEPARATOR, "/", str_replace(DOC_ROOT, $_SERVER['SERVER_NAME'], $this->srcEdit));
# echo "Ajax:{$this->urlWorkWith}";
} else {
$this->urlWorkWith = "http://" . str_replace(DIRECTORY_SEPARATOR, "/", str_replace(DOC_ROOT, $_SERVER['SERVER_NAME'], $srcWorkWith));
# echo "noAjax:{$this->urlWorkWith}";
}
}
function SetSrcPng() {
$arr = explode("/", $this->srcEdit);
$srcPng = PIE_IMAGE_PNG_PATH . $this->AddUserIdToImageSrc($arr[count($arr) - 1]);
$srcPng = substr($srcPng, 0, strripos($srcPng, ".")) . ".png";
$this->srcPng = $srcPng;
}
function SaveOriginal() {
copy($this->srcEdit, $this->srcOriginal);
#Resize to fit in max width/height.
$imageTmp = $this->CreateImage($this->srcOriginal);
$finalWidth = $this->GetWidthFromImage($imageTmp);
$finalHeight = $this->GetHeightFromImage($imageTmp);
$doSave = false;
if ($finalWidth > PIE_IMAGE_MAX_WIDTH) {
$widthProp = PIE_IMAGE_MAX_WIDTH / $finalWidth;
$finalWidth = PIE_IMAGE_MAX_WIDTH;
$finalHeight = round($finalHeight * $widthProp);
$doSave = true;
}
if ($finalHeight > PIE_IMAGE_MAX_HEIGHT) {
$heightProp = PIE_IMAGE_MAX_HEIGHT / $finalHeight;
$finalHeight = PIE_IMAGE_MAX_HEIGHT;
$finalWidth = round($finalWidth * $heightProp);
$doSave = true;
}
if ($doSave) {
$imageTmp = $this->ActionResize($finalWidth, $finalHeight, $imageTmp);
$this->SaveImage($imageTmp, $this->srcOriginal);
}
}
function SavePng() {
$this->SaveImage($this->resourceWorkWith, $this->srcPng, image_type_to_mime_type(IMAGETYPE_PNG));
}
function ErrorHasOccurred() {
return (count($this->errorMessages) > 0);
}
function GetWidthFinal() {
return $this->finalWidth;
}
function GetHeightFinal() {
return $this->finalHeight;
}
function GetWidth() {
return $this->GetWidthFromImage($this->resourceWorkWith);
}
function GetWidthLast() {
if ($this->isPostBack)
return (int) $_POST["widthlast"];
return $this->GetWidth();
}
function GetHeight() {
return $this->GetHeightFromImage($this->resourceWorkWith);
}
function GetHeightLast() {
if ($this->isPostBack)
return (int) $_POST["heightlast"];
return $this->GetWidth();
}
function GetWidthFromImage($image) {
return imagesx($image);
}
function GetHeightFromImage($image) {
return imagesy($image);
}
function Action($actionType) {
$this->doSave = false;
if ($actionType == $this->actionUndo) {
$this->ActionUndo();
$this->doSave = true;
}
if ($actionType == $this->actionUpdate || $actionType == $this->actionSaveAndClose) {
if ($this->inputWidth != $this->GetWidthLast() || $this->inputHeight != $this->GetHeightLast())
$this->actions .= $this->GetActionSeparator() . "resize:" . $this->inputWidth . "," . $this->inputHeight;
if ($this->inputCropLeft != 0 || $this->inputCropRight != 0 || $this->inputCropTop != 0 || $this->inputCropBottom != 0)
$this->actions .= $this->GetActionSeparator() . "crop:" . $this->inputCropLeft . "," . $this->inputCropRight . "," . $this->inputCropTop . "," . $this->inputCropBottom;
$this->doSave = true;
}
if ($actionType == $this->actionUpdate && $this->inputGrayscale) {
if (strpos($this->actions, $this->actionGrayscale) === false) {
$this->actions .= $this->GetActionSeparator() . $this->actionGrayscale . ":0";
$this->doSave = true;
}
} else if ($actionType == $this->actionUpdate && !$this->inputGrayscale) {
if (!(strpos($this->actions, $this->actionGrayscale) === false)) {
$this->actions = str_replace($this->actionGrayscale . ":0" . $this->GetActionSeparator(), "", $this->actions);
$this->actions = str_replace($this->GetActionSeparator() . $this->actionGrayscale . ":0", "", $this->actions);
$this->actions = str_replace($this->actionGrayscale . ":0", "", $this->actions);
$this->doSave = true;
}
}
if ($this->inputContrast != $this->inputContrastLast) {
$this->actions .= $this->GetActionSeparator() . $this->actionContrast . ":" . $this->inputContrast;
$this->doSave = true;
}
if ($this->inputBrightness != $this->inputBrightnessLast) {
$this->actions .= $this->GetActionSeparator() . $this->actionBrightness . ":" . $this->inputBrightness;
$this->doSave = true;
}
if ($this->actionRotateIsSelected) {
if ($this->actionRotate == $this->actionRotateLeft) {
$this->actions .= $this->GetActionSeparator() . $this->actionRotateLeft;
$this->doSave = true;
} else if ($this->actionRotate == $this->actionRotateRight) {
$this->actions .= $this->GetActionSeparator() . $this->actionRotateRight;
$this->doSave = true;
}
}
$finalContrast = 0;
$finalBrightness = 0;
$finalContrastFound = false;
$finalBrightnessFound = false;
$finalGrayscale = false;
if ($this->doSave && $this->actions != "") {
$allActions = explode($this->actionSeparatorSign, $this->actions);
$finalRotate = 0;
$finalCropLeft = 0;
$finalCropRight = 0;
$finalCropTop = 0;
$finalCropBottom = 0;
$doSwitch = false;
foreach ($allActions as $loopAction) {
$actionDetail = explode(":", $loopAction);
$actionValues = explode(",", $actionDetail[1]);
if ($actionDetail[0] == "resize") {
$this->finalWidth = (int) $actionValues[0];
$this->finalHeight = (int) $actionValues[1];
} else if ($actionDetail[0] == "crop") {
$actionValueLeft = (int) $actionValues[0];
$actionValueRight = (int) $actionValues[1];
$actionValueTop = (int) $actionValues[2];
$actionValueBottom = (int) $actionValues[3];
$widthProp = 1;
$heightProp = 1;
if ($doSwitch) {
$widthProp = (($this->GetHeight() - ($finalCropTop + $finalCropBottom)) / $this->finalWidth);
$heightProp = (($this->GetWidth() - ($finalCropLeft + $finalCropRight)) / $this->finalHeight);
} else {
$widthProp = (($this->GetWidth() - ($finalCropLeft + $finalCropRight)) / $this->finalWidth);
$heightProp = (($this->GetHeight() - ($finalCropTop + $finalCropBottom)) / $this->finalHeight);
}
$cropLeft = $actionValueLeft * $widthProp;
$cropRight = $actionValueRight * $widthProp;
$cropTop = $actionValueTop * $heightProp;
$cropBottom = $actionValueBottom * $heightProp;
$cropValues = array();
$cropValues[] = $cropRight;
$cropValues[] = $cropBottom;
$cropValues[] = $cropLeft;
$cropValues[] = $cropTop;
if ($finalRotate != 0)
$cropValues = $this->RotateArray(($finalRotate / -90), $cropValues);
$finalCropRight += $cropValues[0];
$finalCropBottom += $cropValues[1];
$finalCropLeft += $cropValues[2];
$finalCropTop += $cropValues[3];
$this->finalWidth -= ($actionValueLeft + $actionValueRight);
$this->finalHeight -= ($actionValueTop + $actionValueBottom);
}
else if ($actionDetail[0] == $this->actionGrayscale && $this->inputGrayscale) {
$finalGrayscale = true;
} else if ($actionDetail[0] == "contrast") {
$finalContrastFound = true;
$finalContrast = $actionValues[0];
} else if ($actionDetail[0] == "brightness") {
$finalBrightnessFound = true;
$finalBrightness = $actionValues[0];
} else if ($actionDetail[0] == "rotate") {
$finalRotate += (int) $actionValues[0];
$finalWidthTmp = $this->finalWidth;
$this->finalWidth = $this->finalHeight;
$this->finalHeight = $finalWidthTmp;
}
if ($finalRotate == -360 || $finalRotate == 360)
$finalRotate = 0;
$doSwitch = ($finalRotate != 0 && ($finalRotate == 90 || $finalRotate == 270 || $finalRotate == -90 || $finalRotate == -270));
}
//1. All effects.
if ($finalGrayscale)
$this->ActionGrayscale();
if ($finalBrightnessFound)
$this->ActionBrightness($finalBrightness);
if ($finalContrastFound)
$this->ActionContrast($finalContrast * -1);
//2. Do cropping.
$finalCropLeft = round($finalCropLeft);
$finalCropRight = round($finalCropRight);
$finalCropTop = round($finalCropTop);
$finalCropBottom = round($finalCropBottom);
if ($finalCropLeft != 0 || $finalCropRight != 0 || $finalCropTop != 0 || $finalCropBottom != 0)
$this->ActionCrop($finalCropLeft, $finalCropRight, $finalCropTop, $finalCropBottom);
//3. Rotate
if ($finalRotate != 0)
$this->ActionRotate($finalRotate);
//Calculate keep proportions values.
if (round($this->finalWidth / $this->finalHeight, 1) == round($this->GetWidth() / $this->GetHeight(), 1)) {
//It seems to have the same proportions as the original. Use the original proportions value.
$this->widthKeepProportions = $this->GetWidth();
$this->heightKeepProportions = $this->GetHeight();
} else {
//The proportions has been changed. Use the new width and height instead.
$this->widthKeepProportions = $this->finalWidth;
$this->heightKeepProportions = $this->finalHeight;
}
//4. Resize
if ($this->finalWidth > 0 && $this->finalHeight > 0)
$this->resourceWorkWith = $this->ActionResize($this->finalWidth, $this->finalHeight, $this->resourceWorkWith);
$this->SaveImage($this->resourceWorkWith, $this->srcWorkWith, image_type_to_mime_type(IMAGETYPE_PNG));
}
$this->inputBrightness = $finalBrightness;
$this->inputContrast = $finalContrast;
$this->inputGrayscale = $finalGrayscale;
if ($actionType == $this->actionSaveAndClose) {
$this->SaveImage($this->resourceWorkWith, $this->srcEdit, $this->mimeType);
unlink($this->srcOriginal);
unlink($this->srcPng);
unlink($this->srcWorkWith);
PIE_DeleteOldImages(PIE_IMAGE_ORIGINAL_PATH);
PIE_DeleteOldImages(PIE_IMAGE_PNG_PATH);
PIE_DeleteOldImages(PIE_IMAGE_WORK_WITH_PATH);
$reloadParentBrowser = PIE_RELOAD_PARENT_BROWSER_ON_SAVE ? 'window.opener.location.reload();' : '';
// PIE_Echo('<script language="javascript" type="text/javascript">'.$reloadParentBrowser.'window.open(\'\',\'_parent\',\'\');window.close();</script>');
}
}
function ActionResize($width, $height, $image) {
$newImage = @imagecreatetruecolor($width, $height);
PIE_KeepTranspacecyCopyResampled($newImage, $this->mimeType);
imagecopyresampled($newImage, $image, 0, 0, 0, 0, $width, $height, $this->GetWidthFromImage($image), $this->GetHeightFromImage($image));
return $newImage;
}
function ActionCrop($cropLeft, $cropRight, $cropTop, $cropBottom) {
$cropWidth = $this->GetWidth() - $cropLeft - $cropRight;
$cropHeight = $this->GetHeight() - $cropTop - $cropBottom;
$newImageCropped = @imagecreatetruecolor($cropWidth, $cropHeight);
PIE_KeepTranspacecyCopyResampled($newImageCropped, $this->mimeType);
//imagecopy($newImageCropped, $this->resourceWorkWith, 0, 0, $cropLeft, $cropTop, $cropWidth, $cropHeight);
imagecopyresampled($newImageCropped, $this->resourceWorkWith, 0, 0, $cropLeft, $cropTop, $cropWidth, $cropHeight, $cropWidth, $cropHeight);
$this->resourceWorkWith = $newImageCropped;
}
function ActionUndo() {
$separatorPos = strrpos($this->actions, $this->actionSeparatorSign);
if (!($separatorPos === false)) {
$this->actions = substr($this->actions, 0, $separatorPos);
} else {
$this->actions = "";
}
}
function CreateImage($srcEdit) {
$info = getimagesize($srcEdit);
if (!$info)
return NULL;
$mimeType = image_type_to_mime_type($info[2]);
if ($mimeType == image_type_to_mime_type(IMAGETYPE_JPEG)) {
return imagecreatefromjpeg($srcEdit);
} else if ($mimeType == image_type_to_mime_type(IMAGETYPE_GIF)) {
return imagecreatefromgif($srcEdit);
} else if ($mimeType == image_type_to_mime_type(IMAGETYPE_PNG)) {
return imagecreatefrompng($srcEdit);
}
return NULL;
}
function ActionRotate($Degrees) {
if (function_exists('imagerotate'))
$this->resourceWorkWith = imagerotate($this->resourceWorkWith, $Degrees, 0);
else
$this->resourceWorkWith = PIE_ImageRotate($this->resourceWorkWith, $Degrees);
if ($this->mimeType == image_type_to_mime_type(IMAGETYPE_GIF) || $this->mimeType == image_type_to_mime_type(IMAGETYPE_PNG)) {
//Keep transparecy
imagealphablending($this->resourceWorkWith, true);
imagesavealpha($this->resourceWorkWith, true);
}
}
function ActionGrayscale() {
if (function_exists('imagefilter'))
imagefilter($this->resourceWorkWith, IMG_FILTER_GRAYSCALE);
else
PIE_Grayscale($this->resourceWorkWith);
}
function ActionContrast($contrast) {
//-100 = max contrast, 0 = no change, +100 = min contrast
if (function_exists('imagefilter'))
imagefilter($this->resourceWorkWith, IMG_FILTER_CONTRAST, $contrast);
else
PIE_Contrast($this->resourceWorkWith, $contrast);
}
function ActionBrightness($light) {
//-255 = min brightness, 0 = no change, +255 = max brightness
if (function_exists('imagefilter'))
imagefilter($this->resourceWorkWith, IMG_FILTER_BRIGHTNESS, $light);
else
PIE_Brightness($this->resourceWorkWith, $light);
}
function GetErrorMessages() {
if (count($this->errorMessages)) {
PIE_Echo('<div class="error">');
PIE_Echo('<ul>');
foreach ($this->errorMessages as $errorMessage)
PIE_Echo('<li>' . $errorMessage . '</li>');
PIE_Echo("</ul>");
PIE_Echo('</div>');
}
}
function GetActions() {
PIE_Echo($this->actions);
}
function GetActionSeparator() {
if ($this->actions != "")
return $this->actionSeparatorSign;
return "";
}
function SaveImage($image, $toSrc, $mimeType = -1) {
if ($mimeType == -1)
$mimeType = $this->mimeType;
if ($mimeType == image_type_to_mime_type(IMAGETYPE_JPEG)) {
imagejpeg($image, $toSrc);
} else if ($mimeType == image_type_to_mime_type(IMAGETYPE_GIF)) {
imagegif($image, $toSrc);
} else if ($mimeType == image_type_to_mime_type(IMAGETYPE_PNG)) {
//Keep transparecy.
imagesavealpha($image, true);
imagepng($image, $toSrc);
}
}
function CleanUp() {
if ($this->resourceWorkWith)
imagedestroy($this->resourceWorkWith);
}
function RotateArray($numberOfSteps, $arr) {
$finalArray = array();
//-3 to 3
$finalArray[] = $arr[$this->NumberOfStepsCalculator($numberOfSteps + 0)];
$finalArray[] = $arr[$this->NumberOfStepsCalculator($numberOfSteps + 1)];
$finalArray[] = $arr[$this->NumberOfStepsCalculator($numberOfSteps + 2)];
$finalArray[] = $arr[$this->NumberOfStepsCalculator($numberOfSteps + 3)];
return $finalArray;
}
function NumberOfStepsCalculator($sum) {
$maxIndex = 3;
if ($sum > $maxIndex)
return ($sum - $maxIndex) - 1;
else if ($sum < 0) {
return ($sum + $maxIndex) + 1;
}
return $sum;
}
function AddUserIdToImageSrc($imageSrc) {
$name = end(explode(DIRECTORY_SEPARATOR, $imageSrc));
$this->name = $name;
$ext = end(explode('.', $name));
$p = strlen($ext) + 1;
$f = str_replace(substr($imageSrc, -$p), "{$this->userId}.{$ext}", $name);
return $f;
}
function GetFormAction() {
$joomlaIsAdmin = isset($_GET['isadmin']) ? 'isadmin=' . $_GET['isadmin'] . '&' : '';
#return "index.php?".$joomlaIsAdmin.$this->httpImageKey."=".urlencode($this->srcEdit);
return "index.php?" . $joomlaIsAdmin . $this->httpImageKey . "=" . urlencode($this->name);
}
function GetWidthKeepProportions() {
return $this->widthKeepProportions;
}
function GetHeightKeepProportions() {
return $this->heightKeepProportions;
}
$ vim phpimageeditor/lite/shared/index.php
覆盖:
<?php
ini_set('default_charset', 'utf-8');
header("Cache-Control: no-store");
header('content-type: text/html; charset: utf-8');
include 'lite/shared/config.php';
include 'lite/shared/includes/constants.php';
include 'lite/shared/includes/functions.php';
include 'lite/shared/classes/phpimageeditor.php';
global $objPHPImageEditor;
$objPHPImageEditor = new PHPImageEditor();
if (!$objPHPImageEditor->isAjaxPost) { ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>PHP Image Editor</title>
<script type="text/javascript" src="lite/shared/javascript/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="lite/shared/javascript/jquery.jcrop.js"></script>
<script type="text/javascript" src="lite/shared/javascript/jquery.numeric.js"></script>
<script type="text/javascript" src="lite/shared/javascript/jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript" src="lite/shared/javascript/phpimageeditor.js"></script>
<link rel="stylesheet" type="text/css" href="lite/shared/css/style.css"/>
<link rel="stylesheet" type="text/css" href="lite/shared/css/ui.resizable.css"/>
<link rel="stylesheet" type="text/css" href="lite/shared/css/ui.slider.css"/>
<link rel="stylesheet" type="text/css" href="lite/shared/css/jquery.jcrop.css?a=1"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
var ImageMaxWidth = <?php PIE_Echo(PIE_IMAGE_MAX_WIDTH); ?>;
var ImageMaxHeight = <?php PIE_Echo(PIE_IMAGE_MAX_HEIGHT); ?>;
var ImageWidth = <?php PIE_Echo($objPHPImageEditor->GetWidthFinal()); ?>;
var ImageHeight = <?php PIE_Echo($objPHPImageEditor->GetHeightFinal()); ?>;
var TextIsRequired = "<?php PIE_Echo($objPHPImageEditor->texts["IS REQUIRED"]); ?>";
var TextMustBeNumeric = "<?php PIE_Echo($objPHPImageEditor->texts["MUST BE NUMERIC"]); ?>";
var TextWidth = "<?php PIE_Echo($objPHPImageEditor->texts["WIDTH"]); ?>";
var TextHeight = "<?php PIE_Echo($objPHPImageEditor->texts["HEIGHT"]); ?>";
var TextNotNegative = "<?php PIE_Echo($objPHPImageEditor->texts["NOT NEGATIVE"]); ?>";
var TextNotInRange = "<?php PIE_Echo($objPHPImageEditor->texts["NOT IN RANGE"]); ?>";
var TextCantBeLargerThen = "<?php PIE_Echo($objPHPImageEditor->texts["CANT BE LARGER THEN"]); ?>";
var TextAnUnexpectedError = "<?php PIE_Echo($objPHPImageEditor->texts["AN UNEXPECTED ERROR"]); ?>";
var Brightness = <?php PIE_Echo($objPHPImageEditor->inputBrightness); ?>;
var Contrast = <?php PIE_Echo($objPHPImageEditor->inputContrast); ?>;
var BrightnessMax = <?php PIE_Echo($objPHPImageEditor->brightnessMax); ?>;
var ContrastMax = <?php PIE_Echo($objPHPImageEditor->contrastMax); ?>;
var FormAction = "<?php PIE_Echo($objPHPImageEditor->GetFormAction()); ?>";
var FormId = "<?php PIE_Echo($objPHPImageEditor->formName); ?>";
var ActionUpdate = "<?php PIE_Echo($objPHPImageEditor->actionUpdate); ?>";
var ActionUndo = "<?php PIE_Echo($objPHPImageEditor->actionUndo); ?>";
var ActionSaveAndClose = "<?php PIE_Echo($objPHPImageEditor->actionSaveAndClose); ?>";
var ActionRotateLeft = "<?php PIE_Echo($objPHPImageEditor->actionRotateLeft); ?>";
var ActionRotateRight = "<?php PIE_Echo($objPHPImageEditor->actionRotateRight); ?>";
var ActionSaveAndClose = "<?php PIE_Echo($objPHPImageEditor->actionSaveAndClose); ?>";
var MenuResize = "<?php PIE_Echo(PIE_MENU_RESIZE); ?>";
var MenuRotate = "<?php PIE_Echo(PIE_MENU_ROTATE); ?>";
var MenuCrop = "<?php PIE_Echo(PIE_MENU_CROP); ?>";
var MenuEffects = "<?php PIE_Echo(PIE_MENU_EFFECTS); ?>";
var AjaxPostTimeoutMs = <?php PIE_Echo(PIE_AJAX_POST_TIMEOUT_MS); ?>;
var tid = <?php echo $tid?>;
var pid = <?php echo $pid?>;
var uid = <?php echo $uid?>;
var imgName = "<?php echo $img?>";
var Pw = 375;
var Ph = 500;
</script>
</head>
<body>
<div id="phpImageEditor">
<?php } ?>
<form id="<?php PIE_Echo($objPHPImageEditor->formName); ?>" name="<?php PIE_Echo($objPHPImageEditor->formName); ?>" method="post" action="<?php PIE_Echo($objPHPImageEditor->GetFormAction()); ?>">
<?php if (!$objPHPImageEditor->ErrorHasOccurred()) { ?>
<div class="tabs">
<div id="menu">
<?php if (PIE_RESIZE_ENABLED) { ?>
<div class="<?php PIE_Echo($objPHPImageEditor->inputPanel == PIE_MENU_RESIZE ? 'selected' : 'not-selected'); ?>" id="menuitem_<?php PIE_Echo(PIE_MENU_RESIZE); ?>">
<h1><?php PIE_Echo($objPHPImageEditor->texts["RESIZE IMAGE"]); ?></h1>
</div>
<?php } ?>
<?php if (PIE_ROTATE_ENABLED) { ?>
<div class="<?php PIE_Echo($objPHPImageEditor->inputPanel == PIE_MENU_ROTATE ? 'selected' : 'not-selected'); ?>" id="menuitem_<?php PIE_Echo(PIE_MENU_ROTATE); ?>">
<h1><?php PIE_Echo($objPHPImageEditor->texts["ROTATE IMAGE"]); ?></h1>
</div>
<?php } ?>
<?php if (PIE_CROP_ENABLED) { ?>
<!-- <div class="<?php PIE_Echo($objPHPImageEditor->inputPanel == PIE_MENU_CROP ? 'selected' : 'not-selected'); ?>" id="menuitem_<?php PIE_Echo(PIE_MENU_CROP); ?>">
<h1><?php PIE_Echo($objPHPImageEditor->texts["CROP IMAGE"]); ?></h1>
</div>-->
<?php } ?>
<?php if (PIE_EFFECTS_ENABLED) { ?>
<div class="<?php PIE_Echo($objPHPImageEditor->inputPanel == PIE_MENU_EFFECTS ? 'selected' : 'not-selected'); ?>" id="menuitem_<?php PIE_Echo(PIE_MENU_EFFECTS); ?>">
<h1><?php PIE_Echo($objPHPImageEditor->texts["EFFECTS"]); ?></h1>
</div>
<?php } ?>
</div>
<div id="actionContainer">
<div id="panel_<?php PIE_Echo(PIE_MENU_RESIZE); ?>" class="panel">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<div class="field widthAndHeight">
<div class="col-1">
<label for="width"><?php PIE_Echo($objPHPImageEditor->texts["WIDTH"]); ?></label>
<input class="input-number" type="text" name="width" id="width" value="<?php PIE_Echo($objPHPImageEditor->GetWidthFinal()); ?>"/>
<input type="hidden" name="widthoriginal" id="widthoriginal" value="<?php PIE_Echo($objPHPImageEditor->GetWidth()); ?>"/>
</div>
<div class="col-2">
<label for="height"><?php PIE_Echo($objPHPImageEditor->texts["HEIGHT"]); ?></label>
<input class="input-number" type="text" name="height" id="height" value="<?php PIE_Echo($objPHPImageEditor->GetHeightFinal()); ?>"/>
<input type="hidden" name="heightoriginal" id="heightoriginal" value="<?php PIE_Echo($objPHPImageEditor->GetHeight()); ?>"/>
</div>
</div>
<div class="field">
<input class="checkbox" type="checkbox" name="<?php PIE_Echo($objPHPImageEditor->fieldNameKeepProportions); ?>" id="<?php PIE_Echo($objPHPImageEditor->fieldNameKeepProportions); ?>" <?php PIE_Echo($objPHPImageEditor->inputKeepProportions ? 'checked="checked"' : ''); ?>/>
<input type="hidden" name="keepproportionsval" id="keepproportionsval" value="<?php PIE_Echo($objPHPImageEditor->inputKeepProportions ? '1' : '0'); ?>"/>
<label for="<?php PIE_Echo($objPHPImageEditor->fieldNameKeepProportions); ?>" class="checkbox"><?php PIE_Echo($objPHPImageEditor->texts["KEEP PROPORTIONS"]); ?></label>
</div>
</td>
<td>
<div class="help" id="resizehelp">
<div class="help-header" id="resizehelpheader"><?php PIE_Echo($objPHPImageEditor->texts["INSTRUCTIONS"]); ?></div>
<div class="help-content" id="resizehelpcontent"><?php PIE_Echo($objPHPImageEditor->texts["RESIZE HELP"]); ?></div>
</div>
</td>
<td>
<div class="field">
排列序号:<input type="text" name="displayorder" id="picturedisplayorder" value="" onblur="javascript:retry();" style="width:50px;height: 18px;"/>
<br/>
排列位置:<input type="radio" name="coverdisplayposition" value="1" checked />左
<input type="radio" name="coverdisplayposition" value="2" />右
<div>
</td>
<td>
<div class="help" id="kiddlynotice" style="display:none">
<div class="help-header" id="notice">温馨提示</div>
<div class="help-content" id="noticeinfo"></div>
</div>
</td>
</tr>
</table>
<div class="field">
<input class="input-number" type="hidden" name="croptop" id="croptop" value="0"/>
<input class="input-number" type="hidden" name="cropleft" id="cropleft" value="0"/>
<input class="input-number" type="hidden" name="cropright" id="cropright" value="0"/>
<input class="input-number" type="hidden" name="cropbottom" id="cropbottom" value="0"/>
<!-- <div class="help" id="crophelp">
<div class="help-header" id="crophelpheader"><?php PIE_Echo($objPHPImageEditor->texts["INSTRUCTIONS"]); ?></div>
<div class="help-content" id="crophelpcontent"><?php PIE_Echo($objPHPImageEditor->texts["CROP HELP"]); ?></div>
</div>-->
</div>
<div class="field crop-settings">
<div class="crop-top">
<?php PIE_Echo($objPHPImageEditor->texts["CROP WIDTH"]); ?>: <span id="cropwidth" style="display: none">0</span><input type="text" id="Pcropwidth" value="" style="width:50px;" />
<?php PIE_Echo($objPHPImageEditor->texts["CROP HEIGHT"]); ?>: <span id="cropheight" style="display: none">0</span><input type="text" id="Pcropheight" value="" style="width:50px;" />
</div>
<!--<input id="cropkeepproportions" class="checkbox" type="checkbox" name="cropkeepproportions" <?php PIE_Echo($objPHPImageEditor->inputCropKeepProportions ? 'checked="checked"' : ''); ?>/>-->
<!--<label class="checkbox" for="cropkeepproportions"><?php PIE_Echo($objPHPImageEditor->texts["CROP KEEP PROPORTIONS"]); ?></label>-->
<input id="cropkeepproportionsval" type="hidden" name="cropkeepproportionsval" value="<?php PIE_Echo($objPHPImageEditor->inputCropKeepProportions ? '1' : '0'); ?>"/>
<input id="cropkeepproportionsratio" type="hidden" name="cropkeepproportionsratio" value="<?php PIE_Echo($objPHPImageEditor->inputCropKeepProportionsRatio); ?>"/>
</div>
</div>
<div id="panel_<?php PIE_Echo(PIE_MENU_ROTATE); ?>" class="panel">
<div class="field">
<input id="btnRotateLeft" type="button" value="<?php PIE_Echo($objPHPImageEditor->texts["LEFT 90 DEGREES"]); ?>"/>
<input id="btnRotateRight" type="button" value="<?php PIE_Echo($objPHPImageEditor->texts["RIGHT 90 DEGREES"]); ?>"/>
<input type="hidden" name="rotate" id="rotate" value="-1"/>
</div>
</div>
<!-- <div id="panel_<?php PIE_Echo(PIE_MENU_CROP); ?>" class="panel">
<div class="field">
<input class="input-number" type="hidden" name="croptop" id="croptop" value="0"/>
<input class="input-number" type="hidden" name="cropleft" id="cropleft" value="0"/>
<input class="input-number" type="hidden" name="cropright" id="cropright" value="0"/>
<input class="input-number" type="hidden" name="cropbottom" id="cropbottom" value="0"/>
<div class="help" id="crophelp">
<div class="help-header" id="crophelpheader"><?php PIE_Echo($objPHPImageEditor->texts["INSTRUCTIONS"]); ?></div>
<div class="help-content" id="crophelpcontent"><?php PIE_Echo($objPHPImageEditor->texts["CROP HELP"]); ?></div>
</div>
</div>
<div class="field crop-settings">
<div class="crop-top">
<?php PIE_Echo($objPHPImageEditor->texts["CROP WIDTH"]); ?>: <span id="cropwidth">0</span>
<?php PIE_Echo($objPHPImageEditor->texts["CROP HEIGHT"]); ?>: <span id="cropheight">0</span>
</div>
<input id="cropkeepproportions" class="checkbox" type="checkbox" name="cropkeepproportions" <?php PIE_Echo($objPHPImageEditor->inputCropKeepProportions ? 'checked="checked"' : ''); ?>/>
<label class="checkbox" for="cropkeepproportions"><?php PIE_Echo($objPHPImageEditor->texts["CROP KEEP PROPORTIONS"]); ?></label>
<input id="cropkeepproportionsval" type="hidden" name="cropkeepproportionsval" value="<?php PIE_Echo($objPHPImageEditor->inputCropKeepProportions ? '1' : '0'); ?>"/>
<input id="cropkeepproportionsratio" type="hidden" name="cropkeepproportionsratio" value="<?php PIE_Echo($objPHPImageEditor->inputCropKeepProportionsRatio); ?>"/>
</div>
</div>-->
<div id="panel_<?php PIE_Echo(PIE_MENU_EFFECTS); ?>" class="panel">
<div class="field">
<label for="brightness"><?php PIE_Echo($objPHPImageEditor->texts["BRIGHTNESS"]); ?></label>
<div id="brightness_slider_track"></div>
</div>
<input type="hidden" name="brightness" id="brightness" value="<?php PIE_Echo($objPHPImageEditor->inputBrightness); ?>"/>
<div class="field">
<label for="contrast"><?php PIE_Echo($objPHPImageEditor->texts["CONTRAST"]); ?></label>
<div id="contrast_slider_track"></div>
</div>
<input type="hidden" name="contrast" id="contrast" value="<?php PIE_Echo($objPHPImageEditor->inputContrast); ?>"/>
<div class="field">
<input class="checkbox" type="checkbox" name="<?php PIE_Echo($objPHPImageEditor->actionGrayscale); ?>" id="<?php PIE_Echo($objPHPImageEditor->actionGrayscale); ?>" <?php PIE_Echo($objPHPImageEditor->inputGrayscale ? 'checked="checked"' : ''); ?>/>
<label for="<?php PIE_Echo($objPHPImageEditor->actionGrayscale); ?>" class="checkbox"><?php PIE_Echo($objPHPImageEditor->texts["GRAYSCALE"]); ?></label>
<input type="hidden" name="grayscaleval" id="grayscaleval" value="<?php PIE_Echo($objPHPImageEditor->inputGrayscale ? '1' : '0'); ?>"/>
</div>
</div>
<div id="loading" style="display: none;"><?php PIE_Echo($objPHPImageEditor->texts["LOADING"]); ?>...<div id="loading_bar" style="width: 0px;"></div></div>
</div>
<div class="main-actions">
<input type="button" id="btnupdate" name="btnupdate" value="<?php PIE_Echo($objPHPImageEditor->texts["UPDATE"]); ?>"/>
<input type="button" id="btnsave" name="btnsave" value="<?php PIE_Echo($objPHPImageEditor->texts["SAVE AND CLOSE"]); ?>"/>
<input type="button" <?php PIE_Echo($objPHPImageEditor->actions == "" ? 'disabled="disabled"' : ''); ?> id="btnundo" name="btnundo" value="<?php PIE_Echo($objPHPImageEditor->texts["UNDO"]); ?>"/>
<input type="button" id="uploadCoolyun" name="uploadCoolyun" value="uploadCoolyun"/>
</div>
</div>
<input type="hidden" name="actiontype" id="actiontype" value="<?php PIE_Echo($objPHPImageEditor->actionUpdate); ?>"/>
<input type="hidden" name="panel" id="panel" value="<?php PIE_Echo($objPHPImageEditor->inputPanel); ?>"/>
<input type="hidden" name="language" id="language" value="<?php PIE_Echo($objPHPImageEditor->inputLanguage); ?>"/>
<textarea name="actions" id="actions"><?php $objPHPImageEditor->GetActions(); ?></textarea>
<input type="hidden" name="widthlast" id="widthlast" value="<?php PIE_Echo($objPHPImageEditor->GetWidthFinal()); ?>"/>
<input type="hidden" name="heightlast" id="heightlast" value="<?php PIE_Echo($objPHPImageEditor->GetHeightFinal()); ?>"/>
<input type="hidden" name="widthlastbeforeresize" id="widthlastbeforeresize" value="<?php PIE_Echo($objPHPImageEditor->GetWidthKeepProportions()); ?>"/>
<input type="hidden" name="heightlastbeforeresize" id="heightlastbeforeresize" value="<?php PIE_Echo($objPHPImageEditor->GetHeightKeepProportions()); ?>"/>
<input type="hidden" name="userid" id="userid" value="<?php PIE_Echo($objPHPImageEditor->userId); ?>"/>
<input type="hidden" name="contrastlast" id="contrastlast" value="<?php PIE_Echo($objPHPImageEditor->inputContrast); ?>"/>
<input type="hidden" name="brightnesslast" id="brightnesslast" value="<?php PIE_Echo($objPHPImageEditor->inputBrightness); ?>"/>
<input type="hidden" name="isajaxpost" id="isajaxpost" value="false"/>
<?php } ?>
</form>
<?php $objPHPImageEditor->GetErrorMessages(); ?>
<div id="divJsErrors" class="error" style="display: none;">
<ul id="ulJsErrors" style="display: none;"><li></li></ul>
</div>
<div><img src="lite/shared/images/empty.gif" alt=""/></div>
<?php if (!$objPHPImageEditor->ErrorHasOccurred()) { ?>
<div id="editimage">
<img id="image"
style="position: absolute; left: 0px; top: 0px; width: <?php PIE_Echo($objPHPImageEditor->GetWidthFinal()); ?>px; height: <?php PIE_Echo($objPHPImageEditor->GetHeightFinal()); ?>px;"
alt=""
src="<?php PIE_Echo($objPHPImageEditor->urlWorkWith); ?>?timestamp=<?php PIE_Echo(time()); ?>"/>
<div id="imageResizerKeepProportions" style="diplay: <?php PIE_Echo(($objPHPImageEditor->inputKeepProportions && $objPHPImageEditor->inputPanel == PIE_MENU_RESIZE) ? 'block' : 'none'); ?>; width: <?php PIE_Echo($objPHPImageEditor->GetWidthFinal()); ?>px; height: <?php PIE_Echo($objPHPImageEditor->GetHeightFinal()); ?>px;"></div>
<div id="imageResizerNoProportions" style="diplay: <?php PIE_Echo((!$objPHPImageEditor->inputKeepProportions && $objPHPImageEditor->inputPanel == PIE_MENU_RESIZE) ? 'block' : 'none'); ?>; width: <?php PIE_Echo($objPHPImageEditor->GetWidthFinal()); ?>px; height: <?php PIE_Echo($objPHPImageEditor->GetHeightFinal()); ?>px;"></div>
</div>
<?php } ?>
<?php if (!$objPHPImageEditor->isAjaxPost) { ?>
</div>
</body>
</html>
<?php } ?>
<?php $objPHPImageEditor->CleanUp(); ?>
$ vim phpimageeditor/lite/shared/javascript/phpimageeditor.js
覆盖:
var objCrop = null;
var act ="block";
function ajax_post()
{
if ($('#loading').css('display') == 'none')
{
$('#width').attr('disabled','disabled');
$('#height').attr('disabled','disabled');
$('#keepproportions').attr('disabled','disabled');
$('#btnRotateLeft').attr('disabled','disabled');
$('#btnRotateRight').attr('disabled','disabled');
$('#croptop').attr('disabled','disabled');
$('#cropbottom').attr('disabled','disabled');
$('#cropleft').attr('disabled','disabled');
$('#cropright').attr('disabled','disabled');
$('#grayscale').attr('disabled','disabled');
$('#btnupdate').attr('disabled','disabled');
$('#btnsave').attr('disabled','disabled');
$('#btnundo').attr('disabled','disabled');
$('#brightness_slider_track').slider('disable');
$('#contrast_slider_track').slider('disable');
$('#loading').css('display','block');
$('#loading_bar').width(0);
$('#loading_bar').animate({width: document.getElementById('loading').offsetWidth-30}, document.getElementById('loading').offsetWidth*10);
$.ajax({
timeout: AjaxPostTimeoutMs,
type: "POST",
url: FormAction,
data: "grayscaleval="+$('#grayscaleval').val()+"&keepproportionsval="+$('#keepproportionsval').val()+"&width="+$('#width').val()+"&widthoriginal="+$('#widthoriginal').val()+"&height="+$('#height').val()+"&heightoriginal="+$('#heightoriginal').val()+"&rotate="+$('#rotate').val()+"&croptop="+$('#croptop').val()+"&cropleft="+$('#cropleft').val()+"&cropright="+$('#cropright').val()+"&cropbottom="+$('#cropbottom').val()+"&contrast="+$('#contrast').val()+"&brightness="+$('#brightness').val()+"&actiontype="+$('#actiontype').val()+"&panel="+$('#panel').val()+"&language="+$('#language').val()+"&actions="+$('#actions').val()+"&widthlast="+$('#widthlast').val()+"&heightlast="+$('#heightlast').val()+"&userid="+$('#userid').val()+"&contrastlast="+$('#contrastlast').val()+"&brightnesslast="+$('#brightnesslast').val()+"&widthlastbeforeresize="+$('#widthlastbeforeresize').val()+"&heightlastbeforeresize="+$('#heightlastbeforeresize').val()+"&cropkeepproportionsval="+$('#cropkeepproportionsval').val()+"&cropkeepproportionsratio="+$('#cropkeepproportionsratio').val()+"&isajaxpost=true",
success: function(data)
{
$('#phpImageEditor').html(data);
activate_form();
phpimageeditor_crop_activator(parseInt($('#panel').val()));
phpimageeditor_init();
$('#loading_bar').stop();
//$('#loading').css('display','none');
},
error: function(XMLHttpRequest, textStatus, errorThrown)
{
activate_form();
$('#ulJsErrors').html("");
adderror(TextAnUnexpectedError);
$('#divJsErrors').css('display','block');
$('#ulJsErrors').css('display','block');
phpimageeditor_crop_activator(parseInt($('#panel').val()));
$('#loading_bar').stop();
//$('#loading').css('display','none');
}
});
}
}
function isinteger(s)
{
var i;
if (isempty(s))
if (isinteger.arguments.length == 1) return 0;
else return (isinteger.arguments[1] == true);
for (i = 0; i < s.length; i++)
{
var c = s.charAt(i);
if (!isdigit(c)) return false;
}
return true;
}
function focus_on_enter(element, event)
{
if(event.keyCode == 13)
element.focus();
}
function reload_mouse_crop()
{
objCrop.destroy();
objCrop = $.Jcrop('#image',{onChange: set_crop_values,onSelect: set_crop_values, aspectRatio: $("input#cropkeepproportions").attr('checked') ? $("#cropkeepproportionsratio").val() : 0});
// $(".jcrop-holder").css("display", "none");
// add by zengyueming Todo 图片大小变化时依然显示剪裁框
objCrop.setSelect([ 0, 0, Pw, Ph ]);
$(".jcrop-holder").css("display", "block");
// end
$("#image").css("display", "block");
}
function update_width(InputWidth, EditForm)
{
if (isinteger(InputWidth.val()))
{
var Width = parseInt($('#width').val());
var Height = parseInt($('#height').val());
$('#image').css('width',Width+'px');
if ($("input#keepproportions").attr('checked'))
{
$('#image').css('height', get_proportional_height(Width, EditForm) + "px");
$('#height').val(get_proportional_height(Width, EditForm));
}
update_mouse_resizer();
reload_mouse_crop();
}
}
function update_mouse_resizer()
{
$('#imageResizerKeepProportions').css('width',$('#width').val()+'px');
$('#imageResizerKeepProportions').css('height',$('#height').val()+'px');
$('#imageResizerNoProportions').css('width',$('#width').val()+'px');
$('#imageResizerNoProportions').css('height',$('#height').val()+'px');
}
function update_height(InputHeight, EditForm)
{
if (isinteger(InputHeight.val()))
{
var Height = parseInt($('#height').val());
var Width = parseInt($('#width').val());
$('#image').css('height',$('#height').val()+'px');
if ($("input#keepproportions").attr('checked'))
{
$('#image').css('width',get_proportional_width(Height, EditForm)+'px');
$('#width').val(get_proportional_width(Height, EditForm));
}
update_mouse_resizer();
reload_mouse_crop();
}
}
function isempty(s)
{
return ((s == null) || (s.length == 0))
}
function isdigit (c)
{
return ((c >= "0") && (c <= "9"))
}
function isintegerinrange(s, a, b)
{
if (isempty(s))
if (isintegerinrange.arguments.length == 1) return false;
else return (isintegerinrange.arguments[1] == true);
// Catch non-integer strings to avoid creating a NaN below,
// which isn't available on JavaScript 1.0 for Windows.
if (!isinteger(s, false)) return false;
var num = parseInt (s);
return ((num >= a) && (num <= b));
}
function validate_form()
{
var sendForm = true;
var width = $('#width').val();
var height = $('#height').val();
var cropleft = $('#cropleft').val();
var cropright = $('#cropright').val();
var croptop = $('#croptop').val();
var cropbottom = $('#cropbottom').val();
$('#divJsErrors').css('display','none');
$('#ulJsErrors').css('display','none');
$('#ulJsErrors').html("");
if (width == "")
{
adderror("\"" + TextWidth + "\" " + TextIsRequired)
sendForm = false;
}
if (height == "")
{
adderror("\"" + TextHeight + "\" " + TextIsRequired)
sendForm = false;
}
if (!sendForm)
{
$('#divJsErrors').css('display','block');
$('#ulJsErrors').css('display','block');
return sendForm;
}
if (!isinteger(width))
{
adderror("\"" + TextWidth + "\" " + TextMustBeNumeric)
sendForm = false;
}
if (!isinteger(height))
{
adderror("\"" + TextHeight + "\" " + TextMustBeNumeric)
sendForm = false;
}
if (!sendForm)
{
$('#divJsErrors').css('display','block');
$('#ulJsErrors').css('display','block');
return sendForm;
}
width = parseInt(width);
height = parseInt(height);
if (!isintegerinrange(width, 1, ImageMaxWidth))
{
adderror("\"" + TextWidth + "\" " + TextNotInRange + ": 1 - " + ImageMaxWidth)
sendForm = false;
}
if (!isintegerinrange(height, 1, ImageMaxHeight))
{
adderror("\"" + TextHeight + "\" " + TextNotInRange + ": 1 - " + ImageMaxHeight)
sendForm = false;
}
if ($('#textlist').val() == '-1' && $('#text').val() != '')
{
if (!isintegerinrange(textposx, 0, width))
{
adderror("\"" + TextStartPositionX + "\" " + TextNotInRange + ": 1 - " + width)
sendForm = false;
}
if (!isintegerinrange(textposy, 0, height))
{
adderror("\"" + TextStartPositionY + "\" " + TextNotInRange + ": 1 - " + height)
sendForm = false;
}
}
if (!sendForm)
{
$('#divJsErrors').css('display','block');
$('#ulJsErrors').css('display','block');
}
return sendForm;
}
function adderror(ErrorText)
{
$('#ulJsErrors').html($('#ulJsErrors').html()+'<li>'+ErrorText+'</li>');
}
function get_proportional_width(Height, EditForm)
{
var HeightOriginal = parseInt($("#heightlastbeforeresize").val());
var WidthOriginal = parseInt($("#widthlastbeforeresize").val());
return Math.round((WidthOriginal/HeightOriginal)*Height);
}
function get_proportional_height(Width, EditForm)
{
var HeightOriginal = parseInt($("#heightlastbeforeresize").val());
var WidthOriginal = parseInt($("#widthlastbeforeresize").val());
return Math.round((HeightOriginal/WidthOriginal)*Width);
}
function remove_px(Value)
{
return Value.replace("px","");
}
function activate_form()
{
$('#width').removeAttr('disabled');
$('#height').removeAttr('disabled');
$('#keepproportions').removeAttr('disabled');
$('#btnRotateLeft').removeAttr('disabled');
$('#btnRotateRight').removeAttr('disabled');
$('#croptop').removeAttr('disabled');
$('#cropbottom').removeAttr('disabled');
$('#cropleft').removeAttr('disabled');
$('#cropright').removeAttr('disabled');
$('#grayscale').removeAttr('disabled');
$('#btnupdate').removeAttr('disabled');
$('#btnsave').removeAttr('disabled');
$('#btnundo').removeAttr('disabled');
$('#brightness_slider_track').slider('enable');
$('#contrast_slider_track').slider('enable');
if ($('#actions').val() == '')
{
$('#btnundo').attr('disabled','disabled');
$('#btnsave').attr('disabled','disabled');
}
else
{
$('#btnundo').removeAttr('disabled');
$('#btnsave').removeAttr('disabled');
}
}
function set_crop_values(c)
{
if (isinteger($("#height").val()) && isinteger($("#width").val()))
{
$("#croptop").val(c.y);
$("#cropbottom").val(parseInt($("#height").val()) - (c.y + c.h));
$("#cropleft").val(c.x);
$("#cropright").val(parseInt($("#width").val()) - (c.x + c.w));
$("#cropwidth").html(c.w);
$("#cropheight").html(c.h);
//zeny edit by 2015/01/15
$("#Pcropwidth").val(c.w);
$("#Pcropheight").val(c.h);
}
}
function phpimageeditor_resize_activator(selectedIndex)
{
if (selectedIndex == MenuResize)
{
if ($('#keepproportionsval').val() == "1")
{
$("#imageResizerKeepProportions").css("display", "block");
$("#imageResizerNoProportions").css("display", "none");
}
else
{
$("#imageResizerKeepProportions").css("display", "none");
$("#imageResizerNoProportions").css("display", "block");
}
}
else
{
$("#imageResizerKeepProportions").css("display", "none");
$("#imageResizerNoProportions").css("display", "none");
}
}
function phpimageeditor_panelfade(selectedIndex)
{
for (i = 0; i < 4; i++)
{
if ($('#panel_'+i) != null)
{
$("#panel_"+i).css('opacity','0.0');
if (i == selectedIndex)
{
$("#menuitem_"+i).removeClass("not-selected");
$("#menuitem_"+i).addClass("selected");
$("#panel_"+i).css('display','block');
$("#panel_"+i).fadeTo("normal", 1.0);
}
else
{
$("#menuitem_"+i).removeClass("selected");
$("#menuitem_"+i).addClass("not-selected");
$("#panel_"+i).css('display','none');
}
}
}
if (selectedIndex != MenuCrop)
{
$("#cropleft").val("0");
$("#cropright").val("0");
$("#croptop").val("0");
$("#cropbottom").val("0");
$("#cropwidth").html("0");
$("#cropheight").html("0");
}
phpimageeditor_resize_activator(selectedIndex);
phpimageeditor_crop_activator(selectedIndex);
$("#panel").val(selectedIndex);
}
function phpimageeditor_crop_activator(selectedIndex)
{
if (objCrop != null)
{
if (selectedIndex != MenuCrop && selectedIndex != MenuResize)
{
objCrop.release();
objCrop.disable();
$(".jcrop-holder").css("display", "none");
$("#image").css("display", "block");
}
else
{
objCrop.release();
objCrop.enable();
console.log(objCrop);
$(".jcrop-holder").css("display", "block");
$("#image").css("display", "block");
// alert(act+'ssss');
if (act != "none"){
objCrop.setSelect([ 0, 0, Pw, Ph ]);
}
}
}
}
function phpimageeditor_init()
{
objCrop = $.Jcrop('#image',{onChange: set_crop_values,onSelect: set_crop_values, aspectRatio: $("input#cropkeepproportions").attr('checked') ? $("input#cropkeepproportionsratio").val() : 0});
$("#imageResizerKeepProportions").resizable(
{
aspectRatio: parseFloat($("input#widthlastbeforeresize").val()) / parseFloat($("input#heightlastbeforeresize").val()),
stop: function(event,ui)
{
var resize_width = parseInt(remove_px($("#imageResizerKeepProportions").css("width")));
var resize_height = parseInt(remove_px($("#imageResizerKeepProportions").css("height")));
$("#image").css("width", resize_width+"px");
$("#image").css("height", resize_height+"px");
$("#width").val(resize_width);
$("#height").val(resize_height);
update_mouse_resizer();
$("#imageResizerKeepProportions").css("opacity", "0.0");
reload_mouse_crop();
},
start: function(event,ui)
{
$("#imageResizerKeepProportions").css("opacity", "0.5");
}
});
$("#imageResizerNoProportions").resizable(
{
aspectRatio: false,
stop: function(event,ui)
{
var resize_width = parseInt(remove_px($("#imageResizerNoProportions").css("width")));
var resize_height = parseInt(remove_px($("#imageResizerNoProportions").css("height")));
$("#image").css("width", resize_width+"px");
$("#image").css("height", resize_height+"px");
$("#width").val(resize_width);
$("#height").val(resize_height);
update_mouse_resizer();
$("#widthlastbeforeresize").val(resize_width);
$("#heightlastbeforeresize").val(resize_height);
$("#imageResizerKeepProportions").resizable('option','aspectRatio',parseFloat($('#widthlastbeforeresize').val())/parseFloat($('#heightlastbeforeresize').val()));
$("#imageResizerNoProportions").css("opacity", "0.0");
reload_mouse_crop();
},
start: function(event,ui)
{
$("#imageResizerNoProportions").css("opacity", "0.5");
}
});
$("#contrast_slider_track").slider({value: parseInt($("#contrast").val()) + ContrastMax, min: 1, max: ((ContrastMax*2)+1), step: 1,
stop: function(event,ui)
{
if (validate_form())
ajax_post();
},
slide: function(event, ui)
{
$("#contrast").val(parseInt(ui.value)-((ContrastMax)+1));
}
});
$("#brightness_slider_track").slider({value: (parseInt($("input#brightness").val())+BrightnessMax),min: 1,max: ((BrightnessMax*2)+1),step: 1,
stop: function(event,ui)
{
if (validate_form())
ajax_post();
},
slide: function(event, ui)
{
$("#brightness").val(parseInt(ui.value)-(BrightnessMax+1));
}
});
$("#grayscale").click(function()
{
if (validate_form())
{
$("#grayscale").attr('checked') ? $('#grayscaleval').val('1') : $('#grayscaleval').val('0');
ajax_post();
}
});
$("#btnupdate").click(function()
{
if (validate_form())
{
act = "none";
$("#actiontype").val(ActionUpdate);
ajax_post();
}
});
$("#btnundo").click(function()
{
if (validate_form())
{
act = "none";
$("#actiontype").val(ActionUndo);
ajax_post();
}
});
$("#btnsave").click(function()
{
if (validate_form())
{
act = "none";
$("#actiontype").val(ActionSaveAndClose);
ajax_post();
}
});
$("#uploadCoolyun").click(function () {
var width = $("#widthoriginal").val(),
height = $("#heightoriginal").val(),
displayorder = $("#picturedisplayorder").val(),
coverdisplayposition = $('input[name="coverdisplayposition"]:checked').val();
$.ajax({
url:"uploadCool.php",
data:{tid:tid,pid:pid,uid:uid,img:imgName,width:width,height:height,displayorder:displayorder,picposition:coverdisplayposition},
type:"post",
dataType:"json",
success : function (msg) {
if (msg.rs==='success'){
alert(msg.info);
}else{
alert(msg.info);
}
}
});
}) ;
retry = function () {
var va = $("#picturedisplayorder").val();
$.ajax({
url:"retryOrd.php",
data:{order:va,tid:tid},
dataType:"json",
type:"post",
success: function (msg){
if(msg.rs==='fail'){
document.getElementById("kiddlynotice").style.display="block";
$("#noticeinfo").html(msg.info);
return;
}
var arr = msg.info.split("_");
Pw = arr[0];Ph=arr[1];
update_mouse_resizer();
reload_mouse_crop();
return;
}
});
};
$("#btnRotateLeft").click(function()
{
if (validate_form())
{
$("#rotate").val(ActionRotateLeft);
ajax_post();
}
});
$("#btnRotateRight").click(function()
{
if (validate_form())
{
$("#rotate").val(ActionRotateRight);
ajax_post();
}
});
$("#btnRotateLeft_text").click(function()
{
if (validate_form())
{
$("#rotatetext").val(ActionRotateLeftText);
ajax_post();
}
});
$("#btnRotateRight_text").click(function()
{
if (validate_form())
{
$("#rotatetext").val(ActionRotateRightText);
ajax_post();
}
});
$("#btnDelete_text").click(function()
{
if (validate_form())
{
$("#deletetext").val(ActionDeleteText);
ajax_post();
}
});
$("form#" + FormId).submit(function()
{
if (validate_form())
{
$("#actiontype").val(ActionSaveAndClose);
return true;
}
return false;
});
$("#textlist").change(function()
{
if (validate_form())
{
$("#actiontype").val(ActionChangeText);
ajax_post();
}
});
$("#width").keydown(function(event)
{
focus_on_enter($("input#btnupdate"), event);
});
$("#width").keyup(function()
{
update_width($(this),$("form#" + FormId));
});
$("#height").keydown(function(event)
{
focus_on_enter($("input#btnupdate"), event);
});
$("#height").keyup(function()
{
update_height($(this),$("form#" + FormId));
});
//edit by 2015/1/14
$("#Pcropwidth").keydown(function (event){
focus_on_enter($("input#btnupdate"), event);
});
$("#Pcropwidth").keyup(function (){
if (isinteger($(this).val())){
console.log($("#Pcropwidth").val());
Pw = parseInt($("#Pcropwidth").val());
update_mouse_resizer();
reload_mouse_crop();
}
});
$("#Pcropheight").keydown(function (event){
focus_on_enter($("input#btnupdate"), event);
});
$("#Pcropheight").keyup(function (){
if (isinteger($(this).val())){
console.log($("#Pcropheight").val());
Ph = parseInt($("#Pcropheight").val());
update_mouse_resizer();
reload_mouse_crop();
}
});
//end
$("#keepproportions").click(function()
{
if ($(this).attr('checked'))
{
$('#keepproportionsval').val('1');
$('#imageResizerKeepProportions').css('display','block');
$('#imageResizerNoProportions').css('display','none');
}
else
{
$('#keepproportionsval').val('0');
$('#imageResizerKeepProportions').css('display','none');
$('#imageResizerNoProportions').css('display','block');
}
});
$("#cropkeepproportions").click(function()
{
if ($(this).attr('checked'))
{
$('#cropkeepproportionsval').val('1');
}
else
{
$('#cropkeepproportionsval').val('0');
}
});
$("#menuitem_" + MenuResize).click(function()
{
if ($('#panel').val() != MenuResize)
{
phpimageeditor_panelfade(MenuResize);
}
});
$("#menuitem_" + MenuRotate).click(function()
{
if ($('#panel').val() != MenuRotate)
{
phpimageeditor_panelfade(MenuRotate);
}
});
$("#menuitem_" + MenuCrop).click(function()
{
if ($('#panel').val() != MenuCrop)
{
phpimageeditor_panelfade(MenuCrop);
}
});
if ($("#menuitem_" + MenuEffects) != null)
{
$("#menuitem_" + MenuEffects).click(function()
{
if ($('#panel').val() != MenuEffects)
{
phpimageeditor_panelfade(MenuEffects);
}
});
}
$('#cropkeepproportions').change(function(e)
{
if (objCrop != null)
{
if (this.checked && parseFloat($("#cropwidth").html()) != 0 && parseFloat($("#cropheight").html()) != 0)
{
var aspectRatio = parseFloat($("#cropwidth").html()) / parseFloat($("#cropheight").html());
objCrop.setOptions({ aspectRatio: aspectRatio });
$("#cropkeepproportionsratio").val(aspectRatio);
}
else if (this.checked && parseFloat($("#cropwidth").html()) == 0 && parseFloat($("#cropheight").html()) == 0)
{
objCrop.setOptions({ aspectRatio: $("#cropkeepproportionsratio").val() });
}
else
{
objCrop.setOptions({ aspectRatio: 0 });
}
}
});
$("input#width").numeric();
$("input#height").numeric();
var selectedIndex = parseInt($('#panel').val());
for (i = 0; i < 4; i++)
{
if ($('#panel_'+i) != null)
{
if (i == selectedIndex)
{
$("#panel_"+i).css('opacity','1.0');
$("#panel_"+i).css('display','block');
}
else
{
$("#panel_"+i).css('opacity','0.0');
$("#panel_"+i).css('display','none');
}
}
}
phpimageeditor_crop_activator(selectedIndex);
phpimageeditor_resize_activator(selectedIndex);
}
$(document).ready(function()
{
phpimageeditor_init();
//add by zengyueming 默认选择第一个menu;
if ($('#panel').val() != MenuResize)
{
$("#Pcropwidth").val(Pw);
$("#Pcropheight").val(Ph);
phpimageeditor_panelfade(MenuResize);
}
//end
});
$ vim phpimageeditor/lite/shared/classes/phpimageeditor.php
覆盖
<?php
class PHPImageEditor {
var $srcEdit = "";
var $name = "";
var $srcOriginal = "";
var $srcPng = "";
var $srcWorkWith = "";
var $urlWorkWith = "";
var $resourceWorkWith = false;
var $mimeType = "";
var $actionSaveAndClose = "save";
var $actionRotateLeft = "rotate:90";
var $actionRotateRight = "rotate:-90";
var $actionGrayscale = "grayscale";
var $actionContrast = "contrast";
var $actionBrightness = "brightness";
var $actionUndo = "undo";
var $actionUpdate = "update";
var $actionRotateIsSelected = false;
var $actionRotate = "";
var $actionSeparatorSign = "#";
var $fieldNameKeepProportions = "keepproportions";
var $errorMessages = array();
var $formName = "phpimageeditor";
var $inputWidth = -1;
var $inputHeight = -1;
var $inputCropLeft = 0;
var $inputCropRight = 0;
var $inputCropTop = 0;
var $inputCropBottom = 0;
var $inputKeepProportions = true;
var $inputCropKeepProportions = false;
var $inputCropKeepProportionsRatio = 1;
var $inputPanel = PIE_START_PANEL;
var $inputLanguage = PIE_DEFAULT_LANGUAGE;
var $inputContrast = 0;
var $inputBrightness = 0;
var $inputContrastLast = 0;
var $inputBrightnessLast = 0;
var $inputGrayscale = false;
var $httpImageKey = "imagesrc";
var $texts = array();
var $actions = "";
var $isPostBack = false;
var $isAjaxPost = false;
var $finalWidth = -1;
var $finalHeight = -1;
var $widthKeepProportions = -1;
var $heightKeepProportions = -1;
var $userId = "";
var $fonts = array();
var $doSave = false;
var $contrastMax = 100;
var $brightnessMax = 255;
// var $photoInfo = array();
function PHPImageEditor() {
$this->LoadLanguage();
if (version_compare(phpversion(), PIE_PHP_VERSION_MINIMUM, "<")) {
$this->errorMessages[] = phpversion() . " " . $this->texts["OLD PHP VERSION"] . " " . PIE_PHP_VERSION_MINIMUM;
return;
}
$this->isPostBack = isset($_POST["actiontype"]);
$srcEdit = "";
if ($_GET[$this->httpImageKey] != NULL) {
$l = DIRECTORY_SEPARATOR;
$file = dirname(dirname(dirname(dirname(__FILE__)))) . "{$l}tmp{$l}{$_GET[$this->httpImageKey]}";
#$srcEdit = strip_tags($_GET[$this->httpImageKey]);
$srcEdit = strip_tags($file);
}
if ($srcEdit == "") {
$this->errorMessages[] = $this->texts["NO PROVIDED IMAGE"];
return;
}
$this->srcEdit = urldecode($srcEdit);
if (isset($_POST["userid"]))
$this->userId = $_POST["userid"];
else {
$this->userId = "_" . str_replace(".", "_", $_SERVER['REMOTE_ADDR']);
#In my Virtual box in Windows Vista I'll get :: as ip.
#Remove it to avoid errors.
$this->userId = str_replace("_::", "", $this->userId);
}
$this->SetSrcOriginal();
$this->SetSrcPng();
$this->SetSrcWorkWith();
if (!file_exists($this->srcEdit)) {
$this->errorMessages[] = $this->texts["IMAGE DOES NOT EXIST"];
return;
}
$info = getimagesize($this->srcEdit);
if (!$info) {
$this->errorMessages[] = $this->texts["INVALID IMAGE TYPE"];
return;
}
$this->mimeType = image_type_to_mime_type($info[2]);
// echo image_type_to_mime_type($info[2])."===".image_type_to_mime_type(IMAGETYPE_JPEG);exit;
if ($this->mimeType == image_type_to_mime_type(IMAGETYPE_JPEG) || $this->mimeType == image_type_to_mime_type(IMAGETYPE_GIF) || $this->mimeType == image_type_to_mime_type(IMAGETYPE_PNG)) {
if (!$this->isPostBack)
$this->SaveOriginal();
$this->resourceWorkWith = $this->CreateImage($this->srcOriginal);
$this->SavePng();
copy($this->srcPng, $this->srcWorkWith);
$this->resourceWorkWith = $this->CreateImage($this->srcPng);
}
else {
$this->errorMessages[] = $this->texts["INVALID IMAGE TYPE"];
return;
}
$this->finalWidth = $this->GetWidth();
$this->finalHeight = $this->GetHeight();
$this->widthKeepProportions = $this->GetWidth();
$this->heightKeepProportions = $this->GetHeight();
// $this->photoInfo = $this->GetUserData();
if ($this->isPostBack) {
$this->actionRotateIsSelected = (strip_tags($_POST["rotate"]) != "-1");
$this->actionRotate = strip_tags($_POST["rotate"]);
$this->actions = strip_tags($_POST["actions"]);
$this->isAjaxPost = (strip_tags($_POST["isajaxpost"]) == "true");
$this->inputWidth = (int) strip_tags($_POST["width"]);
$this->inputHeight = (int) strip_tags($_POST["height"]);
$this->inputCropLeft = (int) strip_tags($_POST["cropleft"]);
$this->inputCropRight = (int) strip_tags($_POST["cropright"]);
$this->inputCropTop = (int) strip_tags($_POST["croptop"]);
$this->inputCropBottom = (int) strip_tags($_POST["cropbottom"]);
$this->inputPanel = (int) strip_tags($_POST["panel"]);
$this->inputLanguage = strip_tags($_POST["language"]);
$this->inputKeepProportions = (strip_tags($_POST["keepproportionsval"]) == "1");
$this->inputCropKeepProportions = (strip_tags($_POST["cropkeepproportionsval"]) == "1");
$this->inputCropKeepProportionsRatio = (float) strip_tags($_POST["cropkeepproportionsratio"]);
$this->inputGrayscale = (strip_tags($_POST["grayscaleval"]) == "1");
$this->inputBrightness = (int) strip_tags($_POST["brightness"]);
$this->inputContrast = (int) strip_tags($_POST["contrast"]);
$this->inputBrightnessLast = (int) strip_tags($_POST["brightnesslast"]);
$this->inputContrastLast = (int) strip_tags($_POST["contrastlast"]);
$this->Action(strip_tags($_POST["actiontype"]));
}
}
function LoadLanguage() {
$language = "";
if (isset($_POST["language"])) {
$this->inputLanguage = $_POST["language"];
$language = $this->inputLanguage;
} else if (isset($_GET["language"])) {
$this->inputLanguage = $_GET["language"];
$language = $this->inputLanguage;
} else
$language = PIE_DEFAULT_LANGUAGE;
$tryLanguage = "language/" . $language . ".ini";
if (file_exists($tryLanguage))
$this->texts = PIE_GetTexts("language/" . $language . ".ini");
else
$this->texts = PIE_GetTexts("language/" . PIE_DEFAULT_LANGUAGE . ".ini");
//Load the texts that not exists in the current langugare from english.
$texts = PIE_GetTexts("language/en-GB.ini");
foreach ($texts as $key => $text) {
if (array_key_exists($key, $this->texts) === false)
$this->texts[$key] = $text;
}
}
function SetSrcOriginal() {
$arr = explode("/", $this->srcEdit);
$this->srcOriginal = PIE_IMAGE_ORIGINAL_PATH . $this->AddUserIdToImageSrc($arr[count($arr) - 1]);
}
function SetSrcWorkWith() {
$arr = explode("/", $this->srcEdit);
$srcWorkWith = PIE_IMAGE_WORK_WITH_PATH . $this->AddUserIdToImageSrc($arr[count($arr) - 1]);
$srcWorkWith = substr($srcWorkWith, 0, strripos($srcWorkWith, ".")) . ".png";
$this->srcWorkWith = $srcWorkWith;
// $this->urlWorkWith = $this->isAjaxPost && $_POST['actiontype'] == $this->actionSaveAndClose
// ? "http://".str_replace(DIRECTORY_SEPARATOR,"/",str_replace(DOC_ROOT,$_SERVER['SERVER_NAME'],$this->srcEdit))
// : "http://".str_replace(DIRECTORY_SEPARATOR,"/",str_replace(DOC_ROOT,$_SERVER['SERVER_NAME'],$srcWorkWith))
// ;
if ($_POST['actiontype'] == $this->actionSaveAndClose) {
$this->urlWorkWith = "http://" . str_replace(DIRECTORY_SEPARATOR, "/", str_replace(DOC_ROOT, $_SERVER['SERVER_NAME'], $this->srcEdit));
# echo "Ajax:{$this->urlWorkWith}";
} else {
$this->urlWorkWith = "http://" . str_replace(DIRECTORY_SEPARATOR, "/", str_replace(DOC_ROOT, $_SERVER['SERVER_NAME'], $srcWorkWith));
# echo "noAjax:{$this->urlWorkWith}";
}
}
function SetSrcPng() {
$arr = explode("/", $this->srcEdit);
$srcPng = PIE_IMAGE_PNG_PATH . $this->AddUserIdToImageSrc($arr[count($arr) - 1]);
$srcPng = substr($srcPng, 0, strripos($srcPng, ".")) . ".png";
$this->srcPng = $srcPng;
}
function SaveOriginal() {
copy($this->srcEdit, $this->srcOriginal);
#Resize to fit in max width/height.
$imageTmp = $this->CreateImage($this->srcOriginal);
$finalWidth = $this->GetWidthFromImage($imageTmp);
$finalHeight = $this->GetHeightFromImage($imageTmp);
$doSave = false;
if ($finalWidth > PIE_IMAGE_MAX_WIDTH) {
$widthProp = PIE_IMAGE_MAX_WIDTH / $finalWidth;
$finalWidth = PIE_IMAGE_MAX_WIDTH;
$finalHeight = round($finalHeight * $widthProp);
$doSave = true;
}
if ($finalHeight > PIE_IMAGE_MAX_HEIGHT) {
$heightProp = PIE_IMAGE_MAX_HEIGHT / $finalHeight;
$finalHeight = PIE_IMAGE_MAX_HEIGHT;
$finalWidth = round($finalWidth * $heightProp);
$doSave = true;
}
if ($doSave) {
$imageTmp = $this->ActionResize($finalWidth, $finalHeight, $imageTmp);
$this->SaveImage($imageTmp, $this->srcOriginal);
}
}
function SavePng() {
$this->SaveImage($this->resourceWorkWith, $this->srcPng, image_type_to_mime_type(IMAGETYPE_PNG));
}
function ErrorHasOccurred() {
return (count($this->errorMessages) > 0);
}
function GetWidthFinal() {
return $this->finalWidth;
}
function GetHeightFinal() {
return $this->finalHeight;
}
function GetWidth() {
return $this->GetWidthFromImage($this->resourceWorkWith);
}
function GetWidthLast() {
if ($this->isPostBack)
return (int) $_POST["widthlast"];
return $this->GetWidth();
}
function GetHeight() {
return $this->GetHeightFromImage($this->resourceWorkWith);
}
function GetHeightLast() {
if ($this->isPostBack)
return (int) $_POST["heightlast"];
return $this->GetWidth();
}
function GetWidthFromImage($image) {
return imagesx($image);
}
function GetHeightFromImage($image) {
return imagesy($image);
}
function Action($actionType) {
$this->doSave = false;
if ($actionType == $this->actionUndo) {
$this->ActionUndo();
$this->doSave = true;
}
if ($actionType == $this->actionUpdate || $actionType == $this->actionSaveAndClose) {
if ($this->inputWidth != $this->GetWidthLast() || $this->inputHeight != $this->GetHeightLast())
$this->actions .= $this->GetActionSeparator() . "resize:" . $this->inputWidth . "," . $this->inputHeight;
if ($this->inputCropLeft != 0 || $this->inputCropRight != 0 || $this->inputCropTop != 0 || $this->inputCropBottom != 0)
$this->actions .= $this->GetActionSeparator() . "crop:" . $this->inputCropLeft . "," . $this->inputCropRight . "," . $this->inputCropTop . "," . $this->inputCropBottom;
$this->doSave = true;
}
if ($actionType == $this->actionUpdate && $this->inputGrayscale) {
if (strpos($this->actions, $this->actionGrayscale) === false) {
$this->actions .= $this->GetActionSeparator() . $this->actionGrayscale . ":0";
$this->doSave = true;
}
} else if ($actionType == $this->actionUpdate && !$this->inputGrayscale) {
if (!(strpos($this->actions, $this->actionGrayscale) === false)) {
$this->actions = str_replace($this->actionGrayscale . ":0" . $this->GetActionSeparator(), "", $this->actions);
$this->actions = str_replace($this->GetActionSeparator() . $this->actionGrayscale . ":0", "", $this->actions);
$this->actions = str_replace($this->actionGrayscale . ":0", "", $this->actions);
$this->doSave = true;
}
}
if ($this->inputContrast != $this->inputContrastLast) {
$this->actions .= $this->GetActionSeparator() . $this->actionContrast . ":" . $this->inputContrast;
$this->doSave = true;
}
if ($this->inputBrightness != $this->inputBrightnessLast) {
$this->actions .= $this->GetActionSeparator() . $this->actionBrightness . ":" . $this->inputBrightness;
$this->doSave = true;
}
if ($this->actionRotateIsSelected) {
if ($this->actionRotate == $this->actionRotateLeft) {
$this->actions .= $this->GetActionSeparator() . $this->actionRotateLeft;
$this->doSave = true;
} else if ($this->actionRotate == $this->actionRotateRight) {
$this->actions .= $this->GetActionSeparator() . $this->actionRotateRight;
$this->doSave = true;
}
}
$finalContrast = 0;
$finalBrightness = 0;
$finalContrastFound = false;
$finalBrightnessFound = false;
$finalGrayscale = false;
if ($this->doSave && $this->actions != "") {
$allActions = explode($this->actionSeparatorSign, $this->actions);
$finalRotate = 0;
$finalCropLeft = 0;
$finalCropRight = 0;
$finalCropTop = 0;
$finalCropBottom = 0;
$doSwitch = false;
foreach ($allActions as $loopAction) {
$actionDetail = explode(":", $loopAction);
$actionValues = explode(",", $actionDetail[1]);
if ($actionDetail[0] == "resize") {
$this->finalWidth = (int) $actionValues[0];
$this->finalHeight = (int) $actionValues[1];
} else if ($actionDetail[0] == "crop") {
$actionValueLeft = (int) $actionValues[0];
$actionValueRight = (int) $actionValues[1];
$actionValueTop = (int) $actionValues[2];
$actionValueBottom = (int) $actionValues[3];
$widthProp = 1;
$heightProp = 1;
if ($doSwitch) {
$widthProp = (($this->GetHeight() - ($finalCropTop + $finalCropBottom)) / $this->finalWidth);
$heightProp = (($this->GetWidth() - ($finalCropLeft + $finalCropRight)) / $this->finalHeight);
} else {
$widthProp = (($this->GetWidth() - ($finalCropLeft + $finalCropRight)) / $this->finalWidth);
$heightProp = (($this->GetHeight() - ($finalCropTop + $finalCropBottom)) / $this->finalHeight);
}
$cropLeft = $actionValueLeft * $widthProp;
$cropRight = $actionValueRight * $widthProp;
$cropTop = $actionValueTop * $heightProp;
$cropBottom = $actionValueBottom * $heightProp;
$cropValues = array();
$cropValues[] = $cropRight;
$cropValues[] = $cropBottom;
$cropValues[] = $cropLeft;
$cropValues[] = $cropTop;
if ($finalRotate != 0)
$cropValues = $this->RotateArray(($finalRotate / -90), $cropValues);
$finalCropRight += $cropValues[0];
$finalCropBottom += $cropValues[1];
$finalCropLeft += $cropValues[2];
$finalCropTop += $cropValues[3];
$this->finalWidth -= ($actionValueLeft + $actionValueRight);
$this->finalHeight -= ($actionValueTop + $actionValueBottom);
}
else if ($actionDetail[0] == $this->actionGrayscale && $this->inputGrayscale) {
$finalGrayscale = true;
} else if ($actionDetail[0] == "contrast") {
$finalContrastFound = true;
$finalContrast = $actionValues[0];
} else if ($actionDetail[0] == "brightness") {
$finalBrightnessFound = true;
$finalBrightness = $actionValues[0];
} else if ($actionDetail[0] == "rotate") {
$finalRotate += (int) $actionValues[0];
$finalWidthTmp = $this->finalWidth;
$this->finalWidth = $this->finalHeight;
$this->finalHeight = $finalWidthTmp;
}
if ($finalRotate == -360 || $finalRotate == 360)
$finalRotate = 0;
$doSwitch = ($finalRotate != 0 && ($finalRotate == 90 || $finalRotate == 270 || $finalRotate == -90 || $finalRotate == -270));
}
//1. All effects.
if ($finalGrayscale)
$this->ActionGrayscale();
if ($finalBrightnessFound)
$this->ActionBrightness($finalBrightness);
if ($finalContrastFound)
$this->ActionContrast($finalContrast * -1);
//2. Do cropping.
$finalCropLeft = round($finalCropLeft);
$finalCropRight = round($finalCropRight);
$finalCropTop = round($finalCropTop);
$finalCropBottom = round($finalCropBottom);
if ($finalCropLeft != 0 || $finalCropRight != 0 || $finalCropTop != 0 || $finalCropBottom != 0)
$this->ActionCrop($finalCropLeft, $finalCropRight, $finalCropTop, $finalCropBottom);
//3. Rotate
if ($finalRotate != 0)
$this->ActionRotate($finalRotate);
//Calculate keep proportions values.
if (round($this->finalWidth / $this->finalHeight, 1) == round($this->GetWidth() / $this->GetHeight(), 1)) {
//It seems to have the same proportions as the original. Use the original proportions value.
$this->widthKeepProportions = $this->GetWidth();
$this->heightKeepProportions = $this->GetHeight();
} else {
//The proportions has been changed. Use the new width and height instead.
$this->widthKeepProportions = $this->finalWidth;
$this->heightKeepProportions = $this->finalHeight;
}
//4. Resize
if ($this->finalWidth > 0 && $this->finalHeight > 0)
$this->resourceWorkWith = $this->ActionResize($this->finalWidth, $this->finalHeight, $this->resourceWorkWith);
$this->SaveImage($this->resourceWorkWith, $this->srcWorkWith, image_type_to_mime_type(IMAGETYPE_PNG));
}
$this->inputBrightness = $finalBrightness;
$this->inputContrast = $finalContrast;
$this->inputGrayscale = $finalGrayscale;
if ($actionType == $this->actionSaveAndClose) {
$this->SaveImage($this->resourceWorkWith, $this->srcEdit, $this->mimeType);
unlink($this->srcOriginal);
unlink($this->srcPng);
unlink($this->srcWorkWith);
PIE_DeleteOldImages(PIE_IMAGE_ORIGINAL_PATH);
PIE_DeleteOldImages(PIE_IMAGE_PNG_PATH);
PIE_DeleteOldImages(PIE_IMAGE_WORK_WITH_PATH);
$reloadParentBrowser = PIE_RELOAD_PARENT_BROWSER_ON_SAVE ? 'window.opener.location.reload();' : '';
// PIE_Echo('<script language="javascript" type="text/javascript">'.$reloadParentBrowser.'window.open(\'\',\'_parent\',\'\');window.close();</script>');
}
}
function ActionResize($width, $height, $image) {
$newImage = @imagecreatetruecolor($width, $height);
PIE_KeepTranspacecyCopyResampled($newImage, $this->mimeType);
imagecopyresampled($newImage, $image, 0, 0, 0, 0, $width, $height, $this->GetWidthFromImage($image), $this->GetHeightFromImage($image));
return $newImage;
}
function ActionCrop($cropLeft, $cropRight, $cropTop, $cropBottom) {
$cropWidth = $this->GetWidth() - $cropLeft - $cropRight;
$cropHeight = $this->GetHeight() - $cropTop - $cropBottom;
$newImageCropped = @imagecreatetruecolor($cropWidth, $cropHeight);
PIE_KeepTranspacecyCopyResampled($newImageCropped, $this->mimeType);
//imagecopy($newImageCropped, $this->resourceWorkWith, 0, 0, $cropLeft, $cropTop, $cropWidth, $cropHeight);
imagecopyresampled($newImageCropped, $this->resourceWorkWith, 0, 0, $cropLeft, $cropTop, $cropWidth, $cropHeight, $cropWidth, $cropHeight);
$this->resourceWorkWith = $newImageCropped;
}
function ActionUndo() {
$separatorPos = strrpos($this->actions, $this->actionSeparatorSign);
if (!($separatorPos === false)) {
$this->actions = substr($this->actions, 0, $separatorPos);
} else {
$this->actions = "";
}
}
function CreateImage($srcEdit) {
$info = getimagesize($srcEdit);
if (!$info)
return NULL;
$mimeType = image_type_to_mime_type($info[2]);
if ($mimeType == image_type_to_mime_type(IMAGETYPE_JPEG)) {
return imagecreatefromjpeg($srcEdit);
} else if ($mimeType == image_type_to_mime_type(IMAGETYPE_GIF)) {
return imagecreatefromgif($srcEdit);
} else if ($mimeType == image_type_to_mime_type(IMAGETYPE_PNG)) {
return imagecreatefrompng($srcEdit);
}
return NULL;
}
function ActionRotate($Degrees) {
if (function_exists('imagerotate'))
$this->resourceWorkWith = imagerotate($this->resourceWorkWith, $Degrees, 0);
else
$this->resourceWorkWith = PIE_ImageRotate($this->resourceWorkWith, $Degrees);
if ($this->mimeType == image_type_to_mime_type(IMAGETYPE_GIF) || $this->mimeType == image_type_to_mime_type(IMAGETYPE_PNG)) {
//Keep transparecy
imagealphablending($this->resourceWorkWith, true);
imagesavealpha($this->resourceWorkWith, true);
}
}
function ActionGrayscale() {
if (function_exists('imagefilter'))
imagefilter($this->resourceWorkWith, IMG_FILTER_GRAYSCALE);
else
PIE_Grayscale($this->resourceWorkWith);
}
function ActionContrast($contrast) {
//-100 = max contrast, 0 = no change, +100 = min contrast
if (function_exists('imagefilter'))
imagefilter($this->resourceWorkWith, IMG_FILTER_CONTRAST, $contrast);
else
PIE_Contrast($this->resourceWorkWith, $contrast);
}
function ActionBrightness($light) {
//-255 = min brightness, 0 = no change, +255 = max brightness
if (function_exists('imagefilter'))
imagefilter($this->resourceWorkWith, IMG_FILTER_BRIGHTNESS, $light);
else
PIE_Brightness($this->resourceWorkWith, $light);
}
function GetErrorMessages() {
if (count($this->errorMessages)) {
PIE_Echo('<div class="error">');
PIE_Echo('<ul>');
foreach ($this->errorMessages as $errorMessage)
PIE_Echo('<li>' . $errorMessage . '</li>');
PIE_Echo("</ul>");
PIE_Echo('</div>');
}
}
function GetActions() {
PIE_Echo($this->actions);
}
function GetActionSeparator() {
if ($this->actions != "")
return $this->actionSeparatorSign;
return "";
}
function SaveImage($image, $toSrc, $mimeType = -1) {
if ($mimeType == -1)
$mimeType = $this->mimeType;
if ($mimeType == image_type_to_mime_type(IMAGETYPE_JPEG)) {
imagejpeg($image, $toSrc);
} else if ($mimeType == image_type_to_mime_type(IMAGETYPE_GIF)) {
imagegif($image, $toSrc);
} else if ($mimeType == image_type_to_mime_type(IMAGETYPE_PNG)) {
//Keep transparecy.
imagesavealpha($image, true);
imagepng($image, $toSrc);
}
}
function CleanUp() {
if ($this->resourceWorkWith)
imagedestroy($this->resourceWorkWith);
}
function RotateArray($numberOfSteps, $arr) {
$finalArray = array();
//-3 to 3
$finalArray[] = $arr[$this->NumberOfStepsCalculator($numberOfSteps + 0)];
$finalArray[] = $arr[$this->NumberOfStepsCalculator($numberOfSteps + 1)];
$finalArray[] = $arr[$this->NumberOfStepsCalculator($numberOfSteps + 2)];
$finalArray[] = $arr[$this->NumberOfStepsCalculator($numberOfSteps + 3)];
return $finalArray;
}
function NumberOfStepsCalculator($sum) {
$maxIndex = 3;
if ($sum > $maxIndex)
return ($sum - $maxIndex) - 1;
else if ($sum < 0) {
return ($sum + $maxIndex) + 1;
}
return $sum;
}
function AddUserIdToImageSrc($imageSrc) {
$name = end(explode(DIRECTORY_SEPARATOR, $imageSrc));
$this->name = $name;
$ext = end(explode('.', $name));
$p = strlen($ext) + 1;
$f = str_replace(substr($imageSrc, -$p), "{$this->userId}.{$ext}", $name);
return $f;
}
function GetFormAction() {
$joomlaIsAdmin = isset($_GET['isadmin']) ? 'isadmin=' . $_GET['isadmin'] . '&' : '';
#return "index.php?".$joomlaIsAdmin.$this->httpImageKey."=".urlencode($this->srcEdit);
return "index.php?" . $joomlaIsAdmin . $this->httpImageKey . "=" . urlencode($this->name);
}
function GetWidthKeepProportions() {
return $this->widthKeepProportions;
}
function GetHeightKeepProportions() {
return $this->heightKeepProportions;
}
$ vim phpimageeditor/lite/shared/index.php
覆盖:
<?php
ini_set('default_charset', 'utf-8');
header("Cache-Control: no-store");
header('content-type: text/html; charset: utf-8');
include 'lite/shared/config.php';
include 'lite/shared/includes/constants.php';
include 'lite/shared/includes/functions.php';
include 'lite/shared/classes/phpimageeditor.php';
global $objPHPImageEditor;
$objPHPImageEditor = new PHPImageEditor();
if (!$objPHPImageEditor->isAjaxPost) { ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>PHP Image Editor</title>
<script type="text/javascript" src="lite/shared/javascript/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="lite/shared/javascript/jquery.jcrop.js"></script>
<script type="text/javascript" src="lite/shared/javascript/jquery.numeric.js"></script>
<script type="text/javascript" src="lite/shared/javascript/jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript" src="lite/shared/javascript/phpimageeditor.js"></script>
<link rel="stylesheet" type="text/css" href="lite/shared/css/style.css"/>
<link rel="stylesheet" type="text/css" href="lite/shared/css/ui.resizable.css"/>
<link rel="stylesheet" type="text/css" href="lite/shared/css/ui.slider.css"/>
<link rel="stylesheet" type="text/css" href="lite/shared/css/jquery.jcrop.css?a=1"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
var ImageMaxWidth = <?php PIE_Echo(PIE_IMAGE_MAX_WIDTH); ?>;
var ImageMaxHeight = <?php PIE_Echo(PIE_IMAGE_MAX_HEIGHT); ?>;
var ImageWidth = <?php PIE_Echo($objPHPImageEditor->GetWidthFinal()); ?>;
var ImageHeight = <?php PIE_Echo($objPHPImageEditor->GetHeightFinal()); ?>;
var TextIsRequired = "<?php PIE_Echo($objPHPImageEditor->texts["IS REQUIRED"]); ?>";
var TextMustBeNumeric = "<?php PIE_Echo($objPHPImageEditor->texts["MUST BE NUMERIC"]); ?>";
var TextWidth = "<?php PIE_Echo($objPHPImageEditor->texts["WIDTH"]); ?>";
var TextHeight = "<?php PIE_Echo($objPHPImageEditor->texts["HEIGHT"]); ?>";
var TextNotNegative = "<?php PIE_Echo($objPHPImageEditor->texts["NOT NEGATIVE"]); ?>";
var TextNotInRange = "<?php PIE_Echo($objPHPImageEditor->texts["NOT IN RANGE"]); ?>";
var TextCantBeLargerThen = "<?php PIE_Echo($objPHPImageEditor->texts["CANT BE LARGER THEN"]); ?>";
var TextAnUnexpectedError = "<?php PIE_Echo($objPHPImageEditor->texts["AN UNEXPECTED ERROR"]); ?>";
var Brightness = <?php PIE_Echo($objPHPImageEditor->inputBrightness); ?>;
var Contrast = <?php PIE_Echo($objPHPImageEditor->inputContrast); ?>;
var BrightnessMax = <?php PIE_Echo($objPHPImageEditor->brightnessMax); ?>;
var ContrastMax = <?php PIE_Echo($objPHPImageEditor->contrastMax); ?>;
var FormAction = "<?php PIE_Echo($objPHPImageEditor->GetFormAction()); ?>";
var FormId = "<?php PIE_Echo($objPHPImageEditor->formName); ?>";
var ActionUpdate = "<?php PIE_Echo($objPHPImageEditor->actionUpdate); ?>";
var ActionUndo = "<?php PIE_Echo($objPHPImageEditor->actionUndo); ?>";
var ActionSaveAndClose = "<?php PIE_Echo($objPHPImageEditor->actionSaveAndClose); ?>";
var ActionRotateLeft = "<?php PIE_Echo($objPHPImageEditor->actionRotateLeft); ?>";
var ActionRotateRight = "<?php PIE_Echo($objPHPImageEditor->actionRotateRight); ?>";
var ActionSaveAndClose = "<?php PIE_Echo($objPHPImageEditor->actionSaveAndClose); ?>";
var MenuResize = "<?php PIE_Echo(PIE_MENU_RESIZE); ?>";
var MenuRotate = "<?php PIE_Echo(PIE_MENU_ROTATE); ?>";
var MenuCrop = "<?php PIE_Echo(PIE_MENU_CROP); ?>";
var MenuEffects = "<?php PIE_Echo(PIE_MENU_EFFECTS); ?>";
var AjaxPostTimeoutMs = <?php PIE_Echo(PIE_AJAX_POST_TIMEOUT_MS); ?>;
var tid = <?php echo $tid?>;
var pid = <?php echo $pid?>;
var uid = <?php echo $uid?>;
var imgName = "<?php echo $img?>";
var Pw = 375;
var Ph = 500;
</script>
</head>
<body>
<div id="phpImageEditor">
<?php } ?>
<form id="<?php PIE_Echo($objPHPImageEditor->formName); ?>" name="<?php PIE_Echo($objPHPImageEditor->formName); ?>" method="post" action="<?php PIE_Echo($objPHPImageEditor->GetFormAction()); ?>">
<?php if (!$objPHPImageEditor->ErrorHasOccurred()) { ?>
<div class="tabs">
<div id="menu">
<?php if (PIE_RESIZE_ENABLED) { ?>
<div class="<?php PIE_Echo($objPHPImageEditor->inputPanel == PIE_MENU_RESIZE ? 'selected' : 'not-selected'); ?>" id="menuitem_<?php PIE_Echo(PIE_MENU_RESIZE); ?>">
<h1><?php PIE_Echo($objPHPImageEditor->texts["RESIZE IMAGE"]); ?></h1>
</div>
<?php } ?>
<?php if (PIE_ROTATE_ENABLED) { ?>
<div class="<?php PIE_Echo($objPHPImageEditor->inputPanel == PIE_MENU_ROTATE ? 'selected' : 'not-selected'); ?>" id="menuitem_<?php PIE_Echo(PIE_MENU_ROTATE); ?>">
<h1><?php PIE_Echo($objPHPImageEditor->texts["ROTATE IMAGE"]); ?></h1>
</div>
<?php } ?>
<?php if (PIE_CROP_ENABLED) { ?>
<!-- <div class="<?php PIE_Echo($objPHPImageEditor->inputPanel == PIE_MENU_CROP ? 'selected' : 'not-selected'); ?>" id="menuitem_<?php PIE_Echo(PIE_MENU_CROP); ?>">
<h1><?php PIE_Echo($objPHPImageEditor->texts["CROP IMAGE"]); ?></h1>
</div>-->
<?php } ?>
<?php if (PIE_EFFECTS_ENABLED) { ?>
<div class="<?php PIE_Echo($objPHPImageEditor->inputPanel == PIE_MENU_EFFECTS ? 'selected' : 'not-selected'); ?>" id="menuitem_<?php PIE_Echo(PIE_MENU_EFFECTS); ?>">
<h1><?php PIE_Echo($objPHPImageEditor->texts["EFFECTS"]); ?></h1>
</div>
<?php } ?>
</div>
<div id="actionContainer">
<div id="panel_<?php PIE_Echo(PIE_MENU_RESIZE); ?>" class="panel">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<div class="field widthAndHeight">
<div class="col-1">
<label for="width"><?php PIE_Echo($objPHPImageEditor->texts["WIDTH"]); ?></label>
<input class="input-number" type="text" name="width" id="width" value="<?php PIE_Echo($objPHPImageEditor->GetWidthFinal()); ?>"/>
<input type="hidden" name="widthoriginal" id="widthoriginal" value="<?php PIE_Echo($objPHPImageEditor->GetWidth()); ?>"/>
</div>
<div class="col-2">
<label for="height"><?php PIE_Echo($objPHPImageEditor->texts["HEIGHT"]); ?></label>
<input class="input-number" type="text" name="height" id="height" value="<?php PIE_Echo($objPHPImageEditor->GetHeightFinal()); ?>"/>
<input type="hidden" name="heightoriginal" id="heightoriginal" value="<?php PIE_Echo($objPHPImageEditor->GetHeight()); ?>"/>
</div>
</div>
<div class="field">
<input class="checkbox" type="checkbox" name="<?php PIE_Echo($objPHPImageEditor->fieldNameKeepProportions); ?>" id="<?php PIE_Echo($objPHPImageEditor->fieldNameKeepProportions); ?>" <?php PIE_Echo($objPHPImageEditor->inputKeepProportions ? 'checked="checked"' : ''); ?>/>
<input type="hidden" name="keepproportionsval" id="keepproportionsval" value="<?php PIE_Echo($objPHPImageEditor->inputKeepProportions ? '1' : '0'); ?>"/>
<label for="<?php PIE_Echo($objPHPImageEditor->fieldNameKeepProportions); ?>" class="checkbox"><?php PIE_Echo($objPHPImageEditor->texts["KEEP PROPORTIONS"]); ?></label>
</div>
</td>
<td>
<div class="help" id="resizehelp">
<div class="help-header" id="resizehelpheader"><?php PIE_Echo($objPHPImageEditor->texts["INSTRUCTIONS"]); ?></div>
<div class="help-content" id="resizehelpcontent"><?php PIE_Echo($objPHPImageEditor->texts["RESIZE HELP"]); ?></div>
</div>
</td>
<td>
<div class="field">
排列序号:<input type="text" name="displayorder" id="picturedisplayorder" value="" onblur="javascript:retry();" style="width:50px;height: 18px;"/>
<br/>
排列位置:<input type="radio" name="coverdisplayposition" value="1" checked />左
<input type="radio" name="coverdisplayposition" value="2" />右
<div>
</td>
<td>
<div class="help" id="kiddlynotice" style="display:none">
<div class="help-header" id="notice">温馨提示</div>
<div class="help-content" id="noticeinfo"></div>
</div>
</td>
</tr>
</table>
<div class="field">
<input class="input-number" type="hidden" name="croptop" id="croptop" value="0"/>
<input class="input-number" type="hidden" name="cropleft" id="cropleft" value="0"/>
<input class="input-number" type="hidden" name="cropright" id="cropright" value="0"/>
<input class="input-number" type="hidden" name="cropbottom" id="cropbottom" value="0"/>
<!-- <div class="help" id="crophelp">
<div class="help-header" id="crophelpheader"><?php PIE_Echo($objPHPImageEditor->texts["INSTRUCTIONS"]); ?></div>
<div class="help-content" id="crophelpcontent"><?php PIE_Echo($objPHPImageEditor->texts["CROP HELP"]); ?></div>
</div>-->
</div>
<div class="field crop-settings">
<div class="crop-top">
<?php PIE_Echo($objPHPImageEditor->texts["CROP WIDTH"]); ?>: <span id="cropwidth" style="display: none">0</span><input type="text" id="Pcropwidth" value="" style="width:50px;" />
<?php PIE_Echo($objPHPImageEditor->texts["CROP HEIGHT"]); ?>: <span id="cropheight" style="display: none">0</span><input type="text" id="Pcropheight" value="" style="width:50px;" />
</div>
<!--<input id="cropkeepproportions" class="checkbox" type="checkbox" name="cropkeepproportions" <?php PIE_Echo($objPHPImageEditor->inputCropKeepProportions ? 'checked="checked"' : ''); ?>/>-->
<!--<label class="checkbox" for="cropkeepproportions"><?php PIE_Echo($objPHPImageEditor->texts["CROP KEEP PROPORTIONS"]); ?></label>-->
<input id="cropkeepproportionsval" type="hidden" name="cropkeepproportionsval" value="<?php PIE_Echo($objPHPImageEditor->inputCropKeepProportions ? '1' : '0'); ?>"/>
<input id="cropkeepproportionsratio" type="hidden" name="cropkeepproportionsratio" value="<?php PIE_Echo($objPHPImageEditor->inputCropKeepProportionsRatio); ?>"/>
</div>
</div>
<div id="panel_<?php PIE_Echo(PIE_MENU_ROTATE); ?>" class="panel">
<div class="field">
<input id="btnRotateLeft" type="button" value="<?php PIE_Echo($objPHPImageEditor->texts["LEFT 90 DEGREES"]); ?>"/>
<input id="btnRotateRight" type="button" value="<?php PIE_Echo($objPHPImageEditor->texts["RIGHT 90 DEGREES"]); ?>"/>
<input type="hidden" name="rotate" id="rotate" value="-1"/>
</div>
</div>
<!-- <div id="panel_<?php PIE_Echo(PIE_MENU_CROP); ?>" class="panel">
<div class="field">
<input class="input-number" type="hidden" name="croptop" id="croptop" value="0"/>
<input class="input-number" type="hidden" name="cropleft" id="cropleft" value="0"/>
<input class="input-number" type="hidden" name="cropright" id="cropright" value="0"/>
<input class="input-number" type="hidden" name="cropbottom" id="cropbottom" value="0"/>
<div class="help" id="crophelp">
<div class="help-header" id="crophelpheader"><?php PIE_Echo($objPHPImageEditor->texts["INSTRUCTIONS"]); ?></div>
<div class="help-content" id="crophelpcontent"><?php PIE_Echo($objPHPImageEditor->texts["CROP HELP"]); ?></div>
</div>
</div>
<div class="field crop-settings">
<div class="crop-top">
<?php PIE_Echo($objPHPImageEditor->texts["CROP WIDTH"]); ?>: <span id="cropwidth">0</span>
<?php PIE_Echo($objPHPImageEditor->texts["CROP HEIGHT"]); ?>: <span id="cropheight">0</span>
</div>
<input id="cropkeepproportions" class="checkbox" type="checkbox" name="cropkeepproportions" <?php PIE_Echo($objPHPImageEditor->inputCropKeepProportions ? 'checked="checked"' : ''); ?>/>
<label class="checkbox" for="cropkeepproportions"><?php PIE_Echo($objPHPImageEditor->texts["CROP KEEP PROPORTIONS"]); ?></label>
<input id="cropkeepproportionsval" type="hidden" name="cropkeepproportionsval" value="<?php PIE_Echo($objPHPImageEditor->inputCropKeepProportions ? '1' : '0'); ?>"/>
<input id="cropkeepproportionsratio" type="hidden" name="cropkeepproportionsratio" value="<?php PIE_Echo($objPHPImageEditor->inputCropKeepProportionsRatio); ?>"/>
</div>
</div>-->
<div id="panel_<?php PIE_Echo(PIE_MENU_EFFECTS); ?>" class="panel">
<div class="field">
<label for="brightness"><?php PIE_Echo($objPHPImageEditor->texts["BRIGHTNESS"]); ?></label>
<div id="brightness_slider_track"></div>
</div>
<input type="hidden" name="brightness" id="brightness" value="<?php PIE_Echo($objPHPImageEditor->inputBrightness); ?>"/>
<div class="field">
<label for="contrast"><?php PIE_Echo($objPHPImageEditor->texts["CONTRAST"]); ?></label>
<div id="contrast_slider_track"></div>
</div>
<input type="hidden" name="contrast" id="contrast" value="<?php PIE_Echo($objPHPImageEditor->inputContrast); ?>"/>
<div class="field">
<input class="checkbox" type="checkbox" name="<?php PIE_Echo($objPHPImageEditor->actionGrayscale); ?>" id="<?php PIE_Echo($objPHPImageEditor->actionGrayscale); ?>" <?php PIE_Echo($objPHPImageEditor->inputGrayscale ? 'checked="checked"' : ''); ?>/>
<label for="<?php PIE_Echo($objPHPImageEditor->actionGrayscale); ?>" class="checkbox"><?php PIE_Echo($objPHPImageEditor->texts["GRAYSCALE"]); ?></label>
<input type="hidden" name="grayscaleval" id="grayscaleval" value="<?php PIE_Echo($objPHPImageEditor->inputGrayscale ? '1' : '0'); ?>"/>
</div>
</div>
<div id="loading" style="display: none;"><?php PIE_Echo($objPHPImageEditor->texts["LOADING"]); ?>...<div id="loading_bar" style="width: 0px;"></div></div>
</div>
<div class="main-actions">
<input type="button" id="btnupdate" name="btnupdate" value="<?php PIE_Echo($objPHPImageEditor->texts["UPDATE"]); ?>"/>
<input type="button" id="btnsave" name="btnsave" value="<?php PIE_Echo($objPHPImageEditor->texts["SAVE AND CLOSE"]); ?>"/>
<input type="button" <?php PIE_Echo($objPHPImageEditor->actions == "" ? 'disabled="disabled"' : ''); ?> id="btnundo" name="btnundo" value="<?php PIE_Echo($objPHPImageEditor->texts["UNDO"]); ?>"/>
<input type="button" id="uploadCoolyun" name="uploadCoolyun" value="uploadCoolyun"/>
</div>
</div>
<input type="hidden" name="actiontype" id="actiontype" value="<?php PIE_Echo($objPHPImageEditor->actionUpdate); ?>"/>
<input type="hidden" name="panel" id="panel" value="<?php PIE_Echo($objPHPImageEditor->inputPanel); ?>"/>
<input type="hidden" name="language" id="language" value="<?php PIE_Echo($objPHPImageEditor->inputLanguage); ?>"/>
<textarea name="actions" id="actions"><?php $objPHPImageEditor->GetActions(); ?></textarea>
<input type="hidden" name="widthlast" id="widthlast" value="<?php PIE_Echo($objPHPImageEditor->GetWidthFinal()); ?>"/>
<input type="hidden" name="heightlast" id="heightlast" value="<?php PIE_Echo($objPHPImageEditor->GetHeightFinal()); ?>"/>
<input type="hidden" name="widthlastbeforeresize" id="widthlastbeforeresize" value="<?php PIE_Echo($objPHPImageEditor->GetWidthKeepProportions()); ?>"/>
<input type="hidden" name="heightlastbeforeresize" id="heightlastbeforeresize" value="<?php PIE_Echo($objPHPImageEditor->GetHeightKeepProportions()); ?>"/>
<input type="hidden" name="userid" id="userid" value="<?php PIE_Echo($objPHPImageEditor->userId); ?>"/>
<input type="hidden" name="contrastlast" id="contrastlast" value="<?php PIE_Echo($objPHPImageEditor->inputContrast); ?>"/>
<input type="hidden" name="brightnesslast" id="brightnesslast" value="<?php PIE_Echo($objPHPImageEditor->inputBrightness); ?>"/>
<input type="hidden" name="isajaxpost" id="isajaxpost" value="false"/>
<?php } ?>
</form>
<?php $objPHPImageEditor->GetErrorMessages(); ?>
<div id="divJsErrors" class="error" style="display: none;">
<ul id="ulJsErrors" style="display: none;"><li></li></ul>
</div>
<div><img src="lite/shared/images/empty.gif" alt=""/></div>
<?php if (!$objPHPImageEditor->ErrorHasOccurred()) { ?>
<div id="editimage">
<img id="image"
style="position: absolute; left: 0px; top: 0px; width: <?php PIE_Echo($objPHPImageEditor->GetWidthFinal()); ?>px; height: <?php PIE_Echo($objPHPImageEditor->GetHeightFinal()); ?>px;"
alt=""
src="<?php PIE_Echo($objPHPImageEditor->urlWorkWith); ?>?timestamp=<?php PIE_Echo(time()); ?>"/>
<div id="imageResizerKeepProportions" style="diplay: <?php PIE_Echo(($objPHPImageEditor->inputKeepProportions && $objPHPImageEditor->inputPanel == PIE_MENU_RESIZE) ? 'block' : 'none'); ?>; width: <?php PIE_Echo($objPHPImageEditor->GetWidthFinal()); ?>px; height: <?php PIE_Echo($objPHPImageEditor->GetHeightFinal()); ?>px;"></div>
<div id="imageResizerNoProportions" style="diplay: <?php PIE_Echo((!$objPHPImageEditor->inputKeepProportions && $objPHPImageEditor->inputPanel == PIE_MENU_RESIZE) ? 'block' : 'none'); ?>; width: <?php PIE_Echo($objPHPImageEditor->GetWidthFinal()); ?>px; height: <?php PIE_Echo($objPHPImageEditor->GetHeightFinal()); ?>px;"></div>
</div>
<?php } ?>
<?php if (!$objPHPImageEditor->isAjaxPost) { ?>
</div>
</body>
</html>
<?php } ?>
<?php $objPHPImageEditor->CleanUp(); ?>
$ vim phpimageeditor/lite/shared/javascript/phpimageeditor.js
覆盖:
var objCrop = null;
var act ="block";
function ajax_post()
{
if ($('#loading').css('display') == 'none')
{
$('#width').attr('disabled','disabled');
$('#height').attr('disabled','disabled');
$('#keepproportions').attr('disabled','disabled');
$('#btnRotateLeft').attr('disabled','disabled');
$('#btnRotateRight').attr('disabled','disabled');
$('#croptop').attr('disabled','disabled');
$('#cropbottom').attr('disabled','disabled');
$('#cropleft').attr('disabled','disabled');
$('#cropright').attr('disabled','disabled');
$('#grayscale').attr('disabled','disabled');
$('#btnupdate').attr('disabled','disabled');
$('#btnsave').attr('disabled','disabled');
$('#btnundo').attr('disabled','disabled');
$('#brightness_slider_track').slider('disable');
$('#contrast_slider_track').slider('disable');
$('#loading').css('display','block');
$('#loading_bar').width(0);
$('#loading_bar').animate({width: document.getElementById('loading').offsetWidth-30}, document.getElementById('loading').offsetWidth*10);
$.ajax({
timeout: AjaxPostTimeoutMs,
type: "POST",
url: FormAction,
data: "grayscaleval="+$('#grayscaleval').val()+"&keepproportionsval="+$('#keepproportionsval').val()+"&width="+$('#width').val()+"&widthoriginal="+$('#widthoriginal').val()+"&height="+$('#height').val()+"&heightoriginal="+$('#heightoriginal').val()+"&rotate="+$('#rotate').val()+"&croptop="+$('#croptop').val()+"&cropleft="+$('#cropleft').val()+"&cropright="+$('#cropright').val()+"&cropbottom="+$('#cropbottom').val()+"&contrast="+$('#contrast').val()+"&brightness="+$('#brightness').val()+"&actiontype="+$('#actiontype').val()+"&panel="+$('#panel').val()+"&language="+$('#language').val()+"&actions="+$('#actions').val()+"&widthlast="+$('#widthlast').val()+"&heightlast="+$('#heightlast').val()+"&userid="+$('#userid').val()+"&contrastlast="+$('#contrastlast').val()+"&brightnesslast="+$('#brightnesslast').val()+"&widthlastbeforeresize="+$('#widthlastbeforeresize').val()+"&heightlastbeforeresize="+$('#heightlastbeforeresize').val()+"&cropkeepproportionsval="+$('#cropkeepproportionsval').val()+"&cropkeepproportionsratio="+$('#cropkeepproportionsratio').val()+"&isajaxpost=true",
success: function(data)
{
$('#phpImageEditor').html(data);
activate_form();
phpimageeditor_crop_activator(parseInt($('#panel').val()));
phpimageeditor_init();
$('#loading_bar').stop();
//$('#loading').css('display','none');
},
error: function(XMLHttpRequest, textStatus, errorThrown)
{
activate_form();
$('#ulJsErrors').html("");
adderror(TextAnUnexpectedError);
$('#divJsErrors').css('display','block');
$('#ulJsErrors').css('display','block');
phpimageeditor_crop_activator(parseInt($('#panel').val()));
$('#loading_bar').stop();
//$('#loading').css('display','none');
}
});
}
}
function isinteger(s)
{
var i;
if (isempty(s))
if (isinteger.arguments.length == 1) return 0;
else return (isinteger.arguments[1] == true);
for (i = 0; i < s.length; i++)
{
var c = s.charAt(i);
if (!isdigit(c)) return false;
}
return true;
}
function focus_on_enter(element, event)
{
if(event.keyCode == 13)
element.focus();
}
function reload_mouse_crop()
{
objCrop.destroy();
objCrop = $.Jcrop('#image',{onChange: set_crop_values,onSelect: set_crop_values, aspectRatio: $("input#cropkeepproportions").attr('checked') ? $("#cropkeepproportionsratio").val() : 0});
// $(".jcrop-holder").css("display", "none");
// add by zengyueming Todo 图片大小变化时依然显示剪裁框
objCrop.setSelect([ 0, 0, Pw, Ph ]);
$(".jcrop-holder").css("display", "block");
// end
$("#image").css("display", "block");
}
function update_width(InputWidth, EditForm)
{
if (isinteger(InputWidth.val()))
{
var Width = parseInt($('#width').val());
var Height = parseInt($('#height').val());
$('#image').css('width',Width+'px');
if ($("input#keepproportions").attr('checked'))
{
$('#image').css('height', get_proportional_height(Width, EditForm) + "px");
$('#height').val(get_proportional_height(Width, EditForm));
}
update_mouse_resizer();
reload_mouse_crop();
}
}
function update_mouse_resizer()
{
$('#imageResizerKeepProportions').css('width',$('#width').val()+'px');
$('#imageResizerKeepProportions').css('height',$('#height').val()+'px');
$('#imageResizerNoProportions').css('width',$('#width').val()+'px');
$('#imageResizerNoProportions').css('height',$('#height').val()+'px');
}
function update_height(InputHeight, EditForm)
{
if (isinteger(InputHeight.val()))
{
var Height = parseInt($('#height').val());
var Width = parseInt($('#width').val());
$('#image').css('height',$('#height').val()+'px');
if ($("input#keepproportions").attr('checked'))
{
$('#image').css('width',get_proportional_width(Height, EditForm)+'px');
$('#width').val(get_proportional_width(Height, EditForm));
}
update_mouse_resizer();
reload_mouse_crop();
}
}
function isempty(s)
{
return ((s == null) || (s.length == 0))
}
function isdigit (c)
{
return ((c >= "0") && (c <= "9"))
}
function isintegerinrange(s, a, b)
{
if (isempty(s))
if (isintegerinrange.arguments.length == 1) return false;
else return (isintegerinrange.arguments[1] == true);
// Catch non-integer strings to avoid creating a NaN below,
// which isn't available on JavaScript 1.0 for Windows.
if (!isinteger(s, false)) return false;
var num = parseInt (s);
return ((num >= a) && (num <= b));
}
function validate_form()
{
var sendForm = true;
var width = $('#width').val();
var height = $('#height').val();
var cropleft = $('#cropleft').val();
var cropright = $('#cropright').val();
var croptop = $('#croptop').val();
var cropbottom = $('#cropbottom').val();
$('#divJsErrors').css('display','none');
$('#ulJsErrors').css('display','none');
$('#ulJsErrors').html("");
if (width == "")
{
adderror("\"" + TextWidth + "\" " + TextIsRequired)
sendForm = false;
}
if (height == "")
{
adderror("\"" + TextHeight + "\" " + TextIsRequired)
sendForm = false;
}
if (!sendForm)
{
$('#divJsErrors').css('display','block');
$('#ulJsErrors').css('display','block');
return sendForm;
}
if (!isinteger(width))
{
adderror("\"" + TextWidth + "\" " + TextMustBeNumeric)
sendForm = false;
}
if (!isinteger(height))
{
adderror("\"" + TextHeight + "\" " + TextMustBeNumeric)
sendForm = false;
}
if (!sendForm)
{
$('#divJsErrors').css('display','block');
$('#ulJsErrors').css('display','block');
return sendForm;
}
width = parseInt(width);
height = parseInt(height);
if (!isintegerinrange(width, 1, ImageMaxWidth))
{
adderror("\"" + TextWidth + "\" " + TextNotInRange + ": 1 - " + ImageMaxWidth)
sendForm = false;
}
if (!isintegerinrange(height, 1, ImageMaxHeight))
{
adderror("\"" + TextHeight + "\" " + TextNotInRange + ": 1 - " + ImageMaxHeight)
sendForm = false;
}
if ($('#textlist').val() == '-1' && $('#text').val() != '')
{
if (!isintegerinrange(textposx, 0, width))
{
adderror("\"" + TextStartPositionX + "\" " + TextNotInRange + ": 1 - " + width)
sendForm = false;
}
if (!isintegerinrange(textposy, 0, height))
{
adderror("\"" + TextStartPositionY + "\" " + TextNotInRange + ": 1 - " + height)
sendForm = false;
}
}
if (!sendForm)
{
$('#divJsErrors').css('display','block');
$('#ulJsErrors').css('display','block');
}
return sendForm;
}
function adderror(ErrorText)
{
$('#ulJsErrors').html($('#ulJsErrors').html()+'<li>'+ErrorText+'</li>');
}
function get_proportional_width(Height, EditForm)
{
var HeightOriginal = parseInt($("#heightlastbeforeresize").val());
var WidthOriginal = parseInt($("#widthlastbeforeresize").val());
return Math.round((WidthOriginal/HeightOriginal)*Height);
}
function get_proportional_height(Width, EditForm)
{
var HeightOriginal = parseInt($("#heightlastbeforeresize").val());
var WidthOriginal = parseInt($("#widthlastbeforeresize").val());
return Math.round((HeightOriginal/WidthOriginal)*Width);
}
function remove_px(Value)
{
return Value.replace("px","");
}
function activate_form()
{
$('#width').removeAttr('disabled');
$('#height').removeAttr('disabled');
$('#keepproportions').removeAttr('disabled');
$('#btnRotateLeft').removeAttr('disabled');
$('#btnRotateRight').removeAttr('disabled');
$('#croptop').removeAttr('disabled');
$('#cropbottom').removeAttr('disabled');
$('#cropleft').removeAttr('disabled');
$('#cropright').removeAttr('disabled');
$('#grayscale').removeAttr('disabled');
$('#btnupdate').removeAttr('disabled');
$('#btnsave').removeAttr('disabled');
$('#btnundo').removeAttr('disabled');
$('#brightness_slider_track').slider('enable');
$('#contrast_slider_track').slider('enable');
if ($('#actions').val() == '')
{
$('#btnundo').attr('disabled','disabled');
$('#btnsave').attr('disabled','disabled');
}
else
{
$('#btnundo').removeAttr('disabled');
$('#btnsave').removeAttr('disabled');
}
}
function set_crop_values(c)
{
if (isinteger($("#height").val()) && isinteger($("#width").val()))
{
$("#croptop").val(c.y);
$("#cropbottom").val(parseInt($("#height").val()) - (c.y + c.h));
$("#cropleft").val(c.x);
$("#cropright").val(parseInt($("#width").val()) - (c.x + c.w));
$("#cropwidth").html(c.w);
$("#cropheight").html(c.h);
//zeny edit by 2015/01/15
$("#Pcropwidth").val(c.w);
$("#Pcropheight").val(c.h);
}
}
function phpimageeditor_resize_activator(selectedIndex)
{
if (selectedIndex == MenuResize)
{
if ($('#keepproportionsval').val() == "1")
{
$("#imageResizerKeepProportions").css("display", "block");
$("#imageResizerNoProportions").css("display", "none");
}
else
{
$("#imageResizerKeepProportions").css("display", "none");
$("#imageResizerNoProportions").css("display", "block");
}
}
else
{
$("#imageResizerKeepProportions").css("display", "none");
$("#imageResizerNoProportions").css("display", "none");
}
}
function phpimageeditor_panelfade(selectedIndex)
{
for (i = 0; i < 4; i++)
{
if ($('#panel_'+i) != null)
{
$("#panel_"+i).css('opacity','0.0');
if (i == selectedIndex)
{
$("#menuitem_"+i).removeClass("not-selected");
$("#menuitem_"+i).addClass("selected");
$("#panel_"+i).css('display','block');
$("#panel_"+i).fadeTo("normal", 1.0);
}
else
{
$("#menuitem_"+i).removeClass("selected");
$("#menuitem_"+i).addClass("not-selected");
$("#panel_"+i).css('display','none');
}
}
}
if (selectedIndex != MenuCrop)
{
$("#cropleft").val("0");
$("#cropright").val("0");
$("#croptop").val("0");
$("#cropbottom").val("0");
$("#cropwidth").html("0");
$("#cropheight").html("0");
}
phpimageeditor_resize_activator(selectedIndex);
phpimageeditor_crop_activator(selectedIndex);
$("#panel").val(selectedIndex);
}
function phpimageeditor_crop_activator(selectedIndex)
{
if (objCrop != null)
{
if (selectedIndex != MenuCrop && selectedIndex != MenuResize)
{
objCrop.release();
objCrop.disable();
$(".jcrop-holder").css("display", "none");
$("#image").css("display", "block");
}
else
{
objCrop.release();
objCrop.enable();
console.log(objCrop);
$(".jcrop-holder").css("display", "block");
$("#image").css("display", "block");
// alert(act+'ssss');
if (act != "none"){
objCrop.setSelect([ 0, 0, Pw, Ph ]);
}
}
}
}
function phpimageeditor_init()
{
objCrop = $.Jcrop('#image',{onChange: set_crop_values,onSelect: set_crop_values, aspectRatio: $("input#cropkeepproportions").attr('checked') ? $("input#cropkeepproportionsratio").val() : 0});
$("#imageResizerKeepProportions").resizable(
{
aspectRatio: parseFloat($("input#widthlastbeforeresize").val()) / parseFloat($("input#heightlastbeforeresize").val()),
stop: function(event,ui)
{
var resize_width = parseInt(remove_px($("#imageResizerKeepProportions").css("width")));
var resize_height = parseInt(remove_px($("#imageResizerKeepProportions").css("height")));
$("#image").css("width", resize_width+"px");
$("#image").css("height", resize_height+"px");
$("#width").val(resize_width);
$("#height").val(resize_height);
update_mouse_resizer();
$("#imageResizerKeepProportions").css("opacity", "0.0");
reload_mouse_crop();
},
start: function(event,ui)
{
$("#imageResizerKeepProportions").css("opacity", "0.5");
}
});
$("#imageResizerNoProportions").resizable(
{
aspectRatio: false,
stop: function(event,ui)
{
var resize_width = parseInt(remove_px($("#imageResizerNoProportions").css("width")));
var resize_height = parseInt(remove_px($("#imageResizerNoProportions").css("height")));
$("#image").css("width", resize_width+"px");
$("#image").css("height", resize_height+"px");
$("#width").val(resize_width);
$("#height").val(resize_height);
update_mouse_resizer();
$("#widthlastbeforeresize").val(resize_width);
$("#heightlastbeforeresize").val(resize_height);
$("#imageResizerKeepProportions").resizable('option','aspectRatio',parseFloat($('#widthlastbeforeresize').val())/parseFloat($('#heightlastbeforeresize').val()));
$("#imageResizerNoProportions").css("opacity", "0.0");
reload_mouse_crop();
},
start: function(event,ui)
{
$("#imageResizerNoProportions").css("opacity", "0.5");
}
});
$("#contrast_slider_track").slider({value: parseInt($("#contrast").val()) + ContrastMax, min: 1, max: ((ContrastMax*2)+1), step: 1,
stop: function(event,ui)
{
if (validate_form())
ajax_post();
},
slide: function(event, ui)
{
$("#contrast").val(parseInt(ui.value)-((ContrastMax)+1));
}
});
$("#brightness_slider_track").slider({value: (parseInt($("input#brightness").val())+BrightnessMax),min: 1,max: ((BrightnessMax*2)+1),step: 1,
stop: function(event,ui)
{
if (validate_form())
ajax_post();
},
slide: function(event, ui)
{
$("#brightness").val(parseInt(ui.value)-(BrightnessMax+1));
}
});
$("#grayscale").click(function()
{
if (validate_form())
{
$("#grayscale").attr('checked') ? $('#grayscaleval').val('1') : $('#grayscaleval').val('0');
ajax_post();
}
});
$("#btnupdate").click(function()
{
if (validate_form())
{
act = "none";
$("#actiontype").val(ActionUpdate);
ajax_post();
}
});
$("#btnundo").click(function()
{
if (validate_form())
{
act = "none";
$("#actiontype").val(ActionUndo);
ajax_post();
}
});
$("#btnsave").click(function()
{
if (validate_form())
{
act = "none";
$("#actiontype").val(ActionSaveAndClose);
ajax_post();
}
});
$("#uploadCoolyun").click(function () {
var width = $("#widthoriginal").val(),
height = $("#heightoriginal").val(),
displayorder = $("#picturedisplayorder").val(),
coverdisplayposition = $('input[name="coverdisplayposition"]:checked').val();
$.ajax({
url:"uploadCool.php",
data:{tid:tid,pid:pid,uid:uid,img:imgName,width:width,height:height,displayorder:displayorder,picposition:coverdisplayposition},
type:"post",
dataType:"json",
success : function (msg) {
if (msg.rs==='success'){
alert(msg.info);
}else{
alert(msg.info);
}
}
});
}) ;
retry = function () {
var va = $("#picturedisplayorder").val();
$.ajax({
url:"retryOrd.php",
data:{order:va,tid:tid},
dataType:"json",
type:"post",
success: function (msg){
if(msg.rs==='fail'){
document.getElementById("kiddlynotice").style.display="block";
$("#noticeinfo").html(msg.info);
return;
}
var arr = msg.info.split("_");
Pw = arr[0];Ph=arr[1];
update_mouse_resizer();
reload_mouse_crop();
return;
}
});
};
$("#btnRotateLeft").click(function()
{
if (validate_form())
{
$("#rotate").val(ActionRotateLeft);
ajax_post();
}
});
$("#btnRotateRight").click(function()
{
if (validate_form())
{
$("#rotate").val(ActionRotateRight);
ajax_post();
}
});
$("#btnRotateLeft_text").click(function()
{
if (validate_form())
{
$("#rotatetext").val(ActionRotateLeftText);
ajax_post();
}
});
$("#btnRotateRight_text").click(function()
{
if (validate_form())
{
$("#rotatetext").val(ActionRotateRightText);
ajax_post();
}
});
$("#btnDelete_text").click(function()
{
if (validate_form())
{
$("#deletetext").val(ActionDeleteText);
ajax_post();
}
});
$("form#" + FormId).submit(function()
{
if (validate_form())
{
$("#actiontype").val(ActionSaveAndClose);
return true;
}
return false;
});
$("#textlist").change(function()
{
if (validate_form())
{
$("#actiontype").val(ActionChangeText);
ajax_post();
}
});
$("#width").keydown(function(event)
{
focus_on_enter($("input#btnupdate"), event);
});
$("#width").keyup(function()
{
update_width($(this),$("form#" + FormId));
});
$("#height").keydown(function(event)
{
focus_on_enter($("input#btnupdate"), event);
});
$("#height").keyup(function()
{
update_height($(this),$("form#" + FormId));
});
//edit by 2015/1/14
$("#Pcropwidth").keydown(function (event){
focus_on_enter($("input#btnupdate"), event);
});
$("#Pcropwidth").keyup(function (){
if (isinteger($(this).val())){
console.log($("#Pcropwidth").val());
Pw = parseInt($("#Pcropwidth").val());
update_mouse_resizer();
reload_mouse_crop();
}
});
$("#Pcropheight").keydown(function (event){
focus_on_enter($("input#btnupdate"), event);
});
$("#Pcropheight").keyup(function (){
if (isinteger($(this).val())){
console.log($("#Pcropheight").val());
Ph = parseInt($("#Pcropheight").val());
update_mouse_resizer();
reload_mouse_crop();
}
});
//end
$("#keepproportions").click(function()
{
if ($(this).attr('checked'))
{
$('#keepproportionsval').val('1');
$('#imageResizerKeepProportions').css('display','block');
$('#imageResizerNoProportions').css('display','none');
}
else
{
$('#keepproportionsval').val('0');
$('#imageResizerKeepProportions').css('display','none');
$('#imageResizerNoProportions').css('display','block');
}
});
$("#cropkeepproportions").click(function()
{
if ($(this).attr('checked'))
{
$('#cropkeepproportionsval').val('1');
}
else
{
$('#cropkeepproportionsval').val('0');
}
});
$("#menuitem_" + MenuResize).click(function()
{
if ($('#panel').val() != MenuResize)
{
phpimageeditor_panelfade(MenuResize);
}
});
$("#menuitem_" + MenuRotate).click(function()
{
if ($('#panel').val() != MenuRotate)
{
phpimageeditor_panelfade(MenuRotate);
}
});
$("#menuitem_" + MenuCrop).click(function()
{
if ($('#panel').val() != MenuCrop)
{
phpimageeditor_panelfade(MenuCrop);
}
});
if ($("#menuitem_" + MenuEffects) != null)
{
$("#menuitem_" + MenuEffects).click(function()
{
if ($('#panel').val() != MenuEffects)
{
phpimageeditor_panelfade(MenuEffects);
}
});
}
$('#cropkeepproportions').change(function(e)
{
if (objCrop != null)
{
if (this.checked && parseFloat($("#cropwidth").html()) != 0 && parseFloat($("#cropheight").html()) != 0)
{
var aspectRatio = parseFloat($("#cropwidth").html()) / parseFloat($("#cropheight").html());
objCrop.setOptions({ aspectRatio: aspectRatio });
$("#cropkeepproportionsratio").val(aspectRatio);
}
else if (this.checked && parseFloat($("#cropwidth").html()) == 0 && parseFloat($("#cropheight").html()) == 0)
{
objCrop.setOptions({ aspectRatio: $("#cropkeepproportionsratio").val() });
}
else
{
objCrop.setOptions({ aspectRatio: 0 });
}
}
});
$("input#width").numeric();
$("input#height").numeric();
var selectedIndex = parseInt($('#panel').val());
for (i = 0; i < 4; i++)
{
if ($('#panel_'+i) != null)
{
if (i == selectedIndex)
{
$("#panel_"+i).css('opacity','1.0');
$("#panel_"+i).css('display','block');
}
else
{
$("#panel_"+i).css('opacity','0.0');
$("#panel_"+i).css('display','none');
}
}
}
phpimageeditor_crop_activator(selectedIndex);
phpimageeditor_resize_activator(selectedIndex);
}
$(document).ready(function()
{
phpimageeditor_init();
//add by zengyueming 默认选择第一个menu;
if ($('#panel').val() != MenuResize)
{
$("#Pcropwidth").val(Pw);
$("#Pcropheight").val(Ph);
phpimageeditor_panelfade(MenuResize);
}
//end
});
发表评论
-
nginx linux 配置文档
2015-06-16 18:13 5551、配置tenginux文档 :http://www.cnbl ... -
yii 框架文档
2015-03-19 11:52 447http://www.yiiframework.com/doc ... -
authcode加密解密
2015-03-02 00:14 1418function authcode_config($strin ... -
javascript checebox 全选与反选
2015-01-21 09:34 776// .checkzeny是checkbox标签类 sele ... -
数组与对象的转换
2014-05-29 00:04 587//php 对象到数组转换 private funct ... -
数组递归方法
2014-05-29 00:02 938$items = array( 1 => arr ... -
基于Ci 框架下qq,新浪第三方登录
2014-05-28 23:58 2295qq配置文件 路径:application/config/is ... -
ubuntu 经验文档
2014-04-21 16:11 540get1,忘记数据库密码解决方案:http://help.al ...
相关推荐
学习资源自用自用自用自用
压缩包内的“mastercam2017车铣复合走心机后处理修改”文件很可能包含了一些预设的或经过修改的后处理模板,这些模板可以直接用于或作为基础进行进一步的个性化调整。用户可以根据自身机床的实际情况,参考这些文件...
一个数据集 自用 自用 自用 自用 自用
该中文驱动为自用DIY版,使用官方中文版32位驱动替换官方英文版64位驱动而来,因修改后驱动版本存在差异,驱动包安装时会有告警提示,选择始终信任安装即可,因使用官方32位中文驱动替换官方64位英文驱动,打印机...
自用后端开发资料包,自用自用
自用蜜蜂剪辑蜜蜂剪辑蜜蜂剪辑蜜蜂剪辑蜜蜂剪辑蜜蜂剪辑蜜蜂剪辑蜜蜂剪辑蜜蜂剪辑蜜蜂剪辑蜜蜂剪辑蜜蜂剪辑蜜蜂剪辑蜜蜂剪辑蜜蜂剪辑蜜蜂剪辑蜜蜂剪辑蜜蜂剪辑蜜蜂剪辑蜜蜂剪辑蜜蜂剪辑蜜蜂剪辑蜜蜂剪辑蜜蜂剪辑蜜蜂...
4. **数据修改**:允许管理员在不影响游戏整体平衡的前提下,对特定玩家的数据进行修改,比如经验值、物品、角色属性等。 5. **安全监控**:可能包含监控和防止作弊的模块,检测不正常的游戏行为。 6. **脚本语言**...
downloading_小月和平自用版美化V10.zip
梦里飞雪自用模块梦里飞雪自用模块梦里飞雪自用模块梦里飞雪自用模块梦里飞雪自用模块梦里飞雪自用模块
小黑自用的DLL库查看器小黑自用的DLL库查看器小黑自用的DLL库查看器小黑自用的DLL库查看器小黑自用的DLL库查看器小黑自用的DLL库查看器小黑自用的DLL库查看器小黑自用的DLL库查看器小黑自用的DLL库查看器小黑自用的...
标题中的“自用数据库管理工具”表明这是一款个人使用的用于管理和操作数据库的应用程序。数据库管理工具通常是用于创建、查看、编辑和管理数据库的软件,它可以帮助用户更方便地执行SQL查询,进行数据备份、恢复,...
自用修改的成交量 副图指标 通达信.doc
小月和平自用版美化V10.zip
自用图库 比较好用的 自用图库 比较好用的 自用图库 比较好用的 自用图库 比较好用的 自用图库 比较好用的 自用图库 比较好用的 自用图库 比较好用的
资源自用生日快乐资源自用
"易语言模块六六自用模块.rar"很可能是一个由用户"六六"创建并个人使用的易语言模块集合,它包含了多个功能模块,方便在易语言编程时调用,提高开发效率。 模块在编程中是将相关功能封装在一起的代码单元,可以看作...
这个“EwebEditor5.5自用修改无限制版.rar”文件是一个经过修改的版本,旨在提供全部功能而没有任何使用限制。在原版EwebEditor的基础上,开发者可能已经去除了某些商业版的限制,比如水印、试用期或功能限制等。 ...
标题中的“多年自用的西门子后处理”暗示了这是一个关于西门子软件的后处理工具集,可能包括了用户个人长期使用并验证过的高效能解决方案。这些工具可能适用于不同的加工场景,为用户提供了优化的模拟、分析和结果...
ps自用笔刷
小月和平自用版美化V5.zip