|
Posted by Manish on 11/19/02 11:47
I am developing a photo gallery.
1. The user will be able to upload the photo
a) Edit the photo using various GD library functions
viz. flip, rotate, ...
2. AJAX is implemented in a small part
--------------------------------------------------------------------------------------------------------------------------------
ajax.php
--------------------------------------------------------------------------------------------------------------------------------
<?php
session_start();
?>
<html>
<head><script src="ajaxjs.js"></script></head>
<body>
<form name="theform" id="theform" action="" method="post">
Original : <img src="photo_full.jpg" border="0">
<br /><br />
Under Edit :
<div id="underEdit"></div>
<br />
<a href="#" onClick='beginEdit("0", "0", "0"); return false;'>Load
Original</a>
<!--
<a href="#" onClick='beginEdit("1", "angle", "-180"); return
false;'>Rotate -180%</a>
<a href="#" onClick='beginEdit("1", "angle", "-90"); return
false;'>Rotate -90%</a>
<a href="#" onClick='beginEdit("1", "angle", "90"); return
false;'>Rotate 90%</a>
<a href="#" onClick='beginEdit("1", "angle", "180"); return
false;'>Rotate 180%</a>
-->
<a href="#" onClick='beginEdit("2", "1", "0"); return false;'>Flip
Vertical</a>
<a href="#" onClick='beginEdit("2", "2", "0"); return false;'>Flip
Horizontal</a>
<br /><br />
</form>
</body>
</html>
<script language="JavaScript">
function beginEdit(edittype, valtype, valvalue) {
showImg(edittype, valtype, valvalue);
}
beginEdit("0", "0", "0");
</script>
--------------------------------------------------------------------------------------------------------------------------------
startedit.php
--------------------------------------------------------------------------------------------------------------------------------
<?php
$edittype = $_GET['edittype'];
$valtype = $_GET['valtype'];
$valvalue = $_GET['valvalue'];
echo ">> _GET >> "; print_r($_GET); echo " >> <br />";
echo '<img
src="getpic.php?edittype='.$edittype.'&valtype='.$valtype.'&valvalue='.$valvalue.'"
/>';
?>
--------------------------------------------------------------------------------------------------------------------------------
getpic.php
--------------------------------------------------------------------------------------------------------------------------------
<?php
session_start();
$edittype = $_GET['edittype'];
$valtype = $_GET['valtype'];
$valvalue = $_GET['valvalue'];
//echo "get = "; print_r($_GET);
//if(count($_SESSION["imagers"])) {
// $imagers = $_SESSION["imagers"][count($_SESSION["imagers"])-1];
//} else {
$image = "photo_full.jpg";
$imagers = LoadJpeg($image);
//}
//$_SESSION["imagers"][count($_SESSION["imagers"])] = $imagers;
if($edittype == "0") {
imagejpeg($imagers);
} else if($edittype == "1") {
} else if($edittype == "2") {
if($valtype == "1") {
imagejpeg(flipImage($imagers, 1, 0));
} else if($valtype == "2") {
imagejpeg(flipImage($imagers, 0, 1));
}
}
function LoadJpeg($imgname)
{
$im = @imagecreatefromjpeg($imgname); /* Attempt to open */
if (!$im) { /* See if it failed */
$im = imagecreatetruecolor(150, 30); /* Create a black image */
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
/* Output an errmsg */
imagestring($im, 1, 5, 5, "Error loading $imgname", $tc);
}
return $im;
}
function flipImage($image, $vertical, $horizontal) {
$w = imagesx($image);
$h = imagesy($image);
if (!$vertical && !$horizontal) return $image;
$flipped = imagecreatetruecolor($w, $h);
if ($vertical) {
for ($y=0; $y<$h; $y++) {
imagecopy($flipped, $image, 0, $y, 0, $h - $y - 1, $w, 1);
}
}
if ($horizontal) {
if ($vertical) {
$image = $flipped;
$flipped = imagecreatetruecolor($w, $h);
}
for ($x=0; $x<$w; $x++) {
imagecopy($flipped, $image, $x, 0, $w - $x - 1, 0, 1, $h);
}
}
return $flipped;
}
?>
--------------------------------------------------------------------------------------------------------------------------------
The problem is that howmuch times I click on Flip Horizontal , it is
done on the original picture, I want it to be on the latest edited one.
Present :
Original >> Flip Horizontal + Flip Horizontal ... >> Flip Horizontal
Needed :
Original >> Flip Horizontal + Flip Horizontal >> Back to Original
I tried using session, but it didn't worked
if(count($_SESSION["imagers"])) {
$imagers = $_SESSION["imagers"][count($_SESSION["imagers"])-1];
} else {
$image = "photo_full.jpg";
$imagers = LoadJpeg($image);
}
$_SESSION["imagers"][count($_SESSION["imagers"])] = $imagers;
Any idea/reference on how to do it.
Thanks.
Navigation:
[Reply to this message]
|