<?php
session_start();
/*
processImage.php
Copyright (C) 2004-2006 Peter Frueh (http://www.ajaxprogrammer.com/)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
Author:
based on Peter Frueh's ImageEditor, <http://ajaxprogrammer.com/>
modified by Andr� Fiedler, <http://visualdrugs.net>
License:
GNU lesser general public license.
*/
// required params: imageName
header('Content-Type: text/plain');
$originalDirectory = getcwd().'/original/';
$activeDirectory = getcwd().'/active/';
$editDirectory = getcwd().'/edit/';
$imageName = $_GET['imageName'];
$action = $_GET['action'];
if(empty($imageName) ||
!file_exists($originalDirectory.$imageName) ||
!file_exists($activeDirectory.$imageName) ||
!file_exists($editDirectory.$imageName)) { echo '({imageFound:false})'; exit; }
if(substr($imageName, 0, 32) != session_id())
{
copy($originalDirectory.$imageName, $originalDirectory.session_id().'_'.$imageName);
copy($originalDirectory.$imageName, $activeDirectory.session_id().'_'.$imageName);
copy($originalDirectory.$imageName, $editDirectory.session_id().'_'.$imageName);
$imageName = session_id().'_'.$imageName;
}
switch($action){
case 'viewOriginal':
copy($originalDirectory.$imageName, $editDirectory.$imageName);
break;
case 'viewActive':
copy($activeDirectory.$imageName, $editDirectory.$imageName);
break;
case 'save':
copy($editDirectory.$imageName, $activeDirectory.$imageName);
break;
case 'resize': // additional required params: w, h
$out_w = $_GET['w'];
$out_h = $_GET['h'];
if (!is_numeric($out_w) || $out_w < 1 || $out_w > 2000 || !is_numeric($out_h) || $out_h < 1 || $out_h > 2000) { exit; }
list($in_w, $in_h) = getimagesize($editDirectory.$imageName);
$in = imagecreatefromjpeg($editDirectory.$imageName);
$out = imagecreatetruecolor($out_w, $out_h);
imagecopyresampled($out, $in, 0, 0, 0, 0, $out_w, $out_h, $in_w, $in_h);
imagejpeg($out, $editDirectory.$imageName, 100);
imagedestroy($in);
imagedestroy($out);
break;
case 'rotate': // additional required params: degrees (90, 180 or 270)
$degrees = $_GET['degrees'];
$in = imagecreatefromjpeg($editDirectory.$imageName);
$out = imagerotate($in, $degrees, 0);
imagejpeg($out, $editDirectory.$imageName, 100);
imagedestroy($in);
imagedestroy($out);
if (($degrees != 90 && $degrees != 180 && $degrees != 270)) { exit; }
$in = imagecreatefromjpeg($editDirectory.$imageName);
if ($degrees == 180){
$out = imagerotate($in, $degrees, 180);
}else{ // 90 or 270
$x = imagesx($in);
$y = imagesy ($in);
$max = max($x, $y);
$square = imagecreatetruecolor($max, $max);
imagecopy($square, $in, 0, 0, 0, 0, $x, $y);
$square = imageRotate($square, $degrees, 0);
$out = imagecreatetruecolor($y, $x);
if ($degrees == 90) {
imagecopy($out, $square, 0, 0, 0, $max - $x, $y, $x);
} elseif ($degrees == 270) {
imagecopy($out, $square, 0, 0, $max - $y, 0, $y, $x);
}
imagedestroy($square);
}
imagejpeg($out, $editDirectory.$imageName, 100);
imagedestroy($in);
imagedestroy($out);
break;
case 'crop': // additional required params: x, y, w, h
$x = $_GET['x'];
$y = $_GET['y'];
$w = $_GET['w'];
$h = $_GET['h'];
if (!is_numeric($x) || !is_numeric($y) || !is_numeric($w) || !is_numeric($h)) { exit; }
$in = imagecreatefromjpeg($editDirectory.$imageName);
$out = imagecreatetruecolor($w, $h);
imagecopyresampled($out, $in, 0, 0, $x, $y, $w, $h, $w, $h);
imagejpeg($out, $editDirectory.$imageName, 100);
imagedestroy($in);
imagedestroy($out);
break;
case 'reduceSaturation':
$in = imagecreatefromjpeg($editDirectory.$imageName);
$x_in = $_GET['x'];
$y_in = $_GET['y'];
$w = $_GET['w'];
$h = $_GET['h'];
for ($x=$x_in; $x<$x_in+$w; $x++) {
for ($y=$y_in; $y<$y_in+$h; $y++) {
$rgb = imagecolorat($in, $x, $y);
$rgb = imagecolorsforindex($in, $rgb);
$grey = ($rgb['red'] + $rgb['green'] + $rgb['blue']) / 3;
imagesetpixel($in, $x, $y, imagecolorallocate($in, $grey, $grey, $grey));
}
}
imagejpeg($in, $editDirectory.$imageName, 100);
imagedestroy($in);
break;
case 'invert':
$in = imagecreatefromjpeg($editDirectory.$imageName);
$x_in = $_GET['x'];
$y_in = $_GET['y'];
$w = $_GET['w'];
$h = $_GET['h'];
for ($x=$x_in; $x<$x_in+$w; $x++) {
for ($y=$y_in; $y<$y_in+$h; $y++) {
$rgb = imagecolorat($in, $x, $y);
$rgb = imagecolorsforindex($in, $rgb);
$r = 255 - $rgb['red'];
$g = 255 - $rgb['green'];
$b = 255 - $rgb['blue'];
imagesetpixel($in, $x, $y, imagecolorallocate($in, $r, $g, $b));
}
}
imagejpeg($in, $editDirectory.$imageName, 100);
imagedestroy($in);
break;
case 'sharpen':
$k = 0.3; // Sharpen (max 1.0)
$in = imagecreatefromjpeg($editDirectory.$imageName);
$w = imagesx($in);
$h = imagesy ($in);
$x_in = $_GET['x'];
$y_in = $_GET['y'];
$w_in = $_GET['w'];
$h_in = $_GET['h'];
$out = imagecreatetruecolor($w_in-2, $h_in-2);
for($x = $x_in+1; $x < $x_in+$w_in-1; $x++) {
for($y = $y_in+1; $y < $y_in+$h_in-1; $y++) {
$rgb[1][0] = imagecolorat($in, $x, $y-1);
$rgb[0][1] = imagecolorat($in, $x-1, $y);
$rgb[1][1] = imagecolorat($in, $x, $y);
$rgb[2][1] = imagecolorat($in, $x+1, $y);
$rgb[1][2] = imagecolorat($in, $x, $y+1);
$r = -$k *(($rgb[1][0] >> 16) & 0xFF) +
-$k *(($rgb[0][1] >> 16) & 0xFF) +
(1+4*$k) *(($rgb[1][1] >> 16) & 0xFF) +
-$k *(($rgb[2][1] >> 16) & 0xFF) +
-$k *(($rgb[1][2] >> 16) & 0xFF) ;
$g = -$k *(($rgb[1][0] >> 8) & 0xFF) +
-$k *(($rgb[0][1] >> 8) & 0xFF) +
(1+4*$k) *(($rgb[1][1] >> 8) & 0xFF) +
-$k *(($rgb[2][1] >> 8) & 0xFF) +
-$k *(($rgb[1][2] >> 8) & 0xFF) ;
$b = -$k *($rgb[1][0] & 0xFF) +
-$k *($rgb[0][1] & 0xFF) +
(1+4*$k) *($rgb[1][1] & 0xFF) +
-$k *($rgb[2][1] & 0xFF) +
-$k *($rgb[1][2] & 0xFF) ;
$r = min(255, max(0, $r));
$g = min(255, max(0, $g));
$b = min(255, max(0, $b));
if(!isset($cols[$r][$g][$b]))
{
$cols[$r][$g][$b] = imagecolorallocate($out, $r, $g, $b);
}
imagesetpixel($out, $x-$x_in-1, $y-$y_in-1, $cols[$r][$g][$b]);
}
}
$out2 = imagecreatetruecolor($w_in, $h_in);
imagecopyresized($out2, $out, 0, 0, 0, 0, $w_in, $h_in, $w_in-2, $h_in-2);
imagedestroy($out);
imagecopy($in, $out2, $x_in, $y_in, 0, 0, $w_in, $h_in);
imagedestroy($out2);
imagejpeg($in, $editDirectory.$imageName, 100);
imagedestroy($in);
break;
case 'contrast':
$brightness=0;
$maxb=0;
$minb=255;
$im = imagecreatefromjpeg($editDirectory.$imageName);
$w = imagesx($im);
$h = imagesy ($im);
for ($x=0; $x<$w; $x++) {
for ($y=0; $y<$h; $y++) {
$rgb=imagecolorat($im, $x, $y);
$rgb=imagecolorsforindex($im, $rgb);
$grey=0.2125*$rgb['red']+0.7154*$rgb['green']+0.0721*$rgb['blue'];
$brightness+=$grey;
if ($grey>$maxb) $maxb=$grey;
if ($grey<$minb) $minb=$grey;
}
}
$brightness=$brightness/($w*$h);
$minb=$brightness/($brightness-$minb);
$maxb=(255-$brightness)/($maxb-$brightness);
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
ImageEditor.rar (13个子文件)
mootools.v1.00.js 83KB
getImage.php 1KB
processImage.php 10KB
index.php 3KB
ImageEditor.js 10KB
edit
flowers.jpg 375KB
frog.jpg 75KB
ImageEditor.css 637B
loading.gif 2KB
active
flowers.jpg 375KB
frog.jpg 75KB
original
flowers.jpg 375KB
frog.jpg 75KB
共 13 条
- 1
资源评论
- 布谷鸟0072013-09-19不错,很好用
- 刘超-ljc2013-05-01挺好的 对我有用
- aa77a2013-05-07没接触过这种在线编辑器,不是吧
mba9001
- 粉丝: 1
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功