$ vim phpimageeditor/lite/shared/classes/phpimageeditor.php
覆盖
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('');
}
}
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('
');
pie_echo('');
foreach ($this->errormessages as $errormessage)
pie_echo('' . $errormessage . '');
pie_echo();
pie_echo('
');
}
}
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 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
覆盖:
isajaxpost) { ?>
php image editor
method=post action=getformaction());%20?>>
errorhasoccurred()) { ?>
>
texts[resize image]); ?>
>
texts[rotate image]); ?>
>
texts[effects]); ?>
texts[width]); ?>
>
>
texts[height]); ?>
>
>
pie_echo>inputkeepproportions ? 'checked=checked' : ''); ?>/>
>
>texts[keep proportions]); ?>
texts[instructions]); ?>
texts[resize help]); ?>
 
