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='beginE dit("0", "0", "0"); return false;'>Load
Original</a>
<!--
<a href="#" onClick='beginE dit("1", "angle", "-180"); return
false;'>Rotate -180%</a>
<a href="#" onClick='beginE dit("1", "angle", "-90"); return
false;'>Rotate -90%</a>
<a href="#" onClick='beginE dit("1", "angle", "90"); return
false;'>Rotate 90%</a>
<a href="#" onClick='beginE dit("1", "angle", "180"); return
false;'>Rotate 180%</a>
-->
<a href="#" onClick='beginE dit("2", "1", "0"); return false;'>Flip
Vertical</a>
<a href="#" onClick='beginE dit("2", "2", "0"); return false;'>Flip
Horizontal</a>
<br /><br />
</form>
</body>
</html>
<script language="JavaS cript">
function beginEdit(editt ype, valtype, valvalue) {
showImg(edittyp e, 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='.$ed ittype.'&valtyp e='.$valtype.'& valvalue='.$val value.'"
/>';
?>
--------------------------------------------------------------------------------------------------------------------------------
getpic.php
--------------------------------------------------------------------------------------------------------------------------------
<?php
session_start() ;
$edittype = $_GET['edittype'];
$valtype = $_GET['valtype'];
$valvalue = $_GET['valvalue'];
//echo "get = "; print_r($_GET);
//if(count($_SESS ION["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($imag ers);
} else if($edittype == "1") {
} else if($edittype == "2") {
if($valtype == "1") {
imagejpeg(flipI mage($imagers, 1, 0));
} else if($valtype == "2") {
imagejpeg(flipI mage($imagers, 0, 1));
}
}
function LoadJpeg($imgna me)
{
$im = @imagecreatefro mjpeg($imgname) ; /* Attempt to open */
if (!$im) { /* See if it failed */
$im = imagecreatetrue color(150, 30); /* Create a black image */
$bgc = imagecoloralloc ate($im, 255, 255, 255);
$tc = imagecoloralloc ate($im, 0, 0, 0);
imagefilledrect angle($im, 0, 0, 150, 30, $bgc);
/* Output an errmsg */
imagestring($im , 1, 5, 5, "Error loading $imgname", $tc);
}
return $im;
}
function flipImage($imag e, $vertical, $horizontal) {
$w = imagesx($image) ;
$h = imagesy($image) ;
if (!$vertical && !$horizontal) return $image;
$flipped = imagecreatetrue color($w, $h);
if ($vertical) {
for ($y=0; $y<$h; $y++) {
imagecopy($flip ped, $image, 0, $y, 0, $h - $y - 1, $w, 1);
}
}
if ($horizontal) {
if ($vertical) {
$image = $flipped;
$flipped = imagecreatetrue color($w, $h);
}
for ($x=0; $x<$w; $x++) {
imagecopy($flip ped, $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($_SESS ION["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.
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='beginE dit("0", "0", "0"); return false;'>Load
Original</a>
<!--
<a href="#" onClick='beginE dit("1", "angle", "-180"); return
false;'>Rotate -180%</a>
<a href="#" onClick='beginE dit("1", "angle", "-90"); return
false;'>Rotate -90%</a>
<a href="#" onClick='beginE dit("1", "angle", "90"); return
false;'>Rotate 90%</a>
<a href="#" onClick='beginE dit("1", "angle", "180"); return
false;'>Rotate 180%</a>
-->
<a href="#" onClick='beginE dit("2", "1", "0"); return false;'>Flip
Vertical</a>
<a href="#" onClick='beginE dit("2", "2", "0"); return false;'>Flip
Horizontal</a>
<br /><br />
</form>
</body>
</html>
<script language="JavaS cript">
function beginEdit(editt ype, valtype, valvalue) {
showImg(edittyp e, 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='.$ed ittype.'&valtyp e='.$valtype.'& valvalue='.$val value.'"
/>';
?>
--------------------------------------------------------------------------------------------------------------------------------
getpic.php
--------------------------------------------------------------------------------------------------------------------------------
<?php
session_start() ;
$edittype = $_GET['edittype'];
$valtype = $_GET['valtype'];
$valvalue = $_GET['valvalue'];
//echo "get = "; print_r($_GET);
//if(count($_SESS ION["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($imag ers);
} else if($edittype == "1") {
} else if($edittype == "2") {
if($valtype == "1") {
imagejpeg(flipI mage($imagers, 1, 0));
} else if($valtype == "2") {
imagejpeg(flipI mage($imagers, 0, 1));
}
}
function LoadJpeg($imgna me)
{
$im = @imagecreatefro mjpeg($imgname) ; /* Attempt to open */
if (!$im) { /* See if it failed */
$im = imagecreatetrue color(150, 30); /* Create a black image */
$bgc = imagecoloralloc ate($im, 255, 255, 255);
$tc = imagecoloralloc ate($im, 0, 0, 0);
imagefilledrect angle($im, 0, 0, 150, 30, $bgc);
/* Output an errmsg */
imagestring($im , 1, 5, 5, "Error loading $imgname", $tc);
}
return $im;
}
function flipImage($imag e, $vertical, $horizontal) {
$w = imagesx($image) ;
$h = imagesy($image) ;
if (!$vertical && !$horizontal) return $image;
$flipped = imagecreatetrue color($w, $h);
if ($vertical) {
for ($y=0; $y<$h; $y++) {
imagecopy($flip ped, $image, 0, $y, 0, $h - $y - 1, $w, 1);
}
}
if ($horizontal) {
if ($vertical) {
$image = $flipped;
$flipped = imagecreatetrue color($w, $h);
}
for ($x=0; $x<$w; $x++) {
imagecopy($flip ped, $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($_SESS ION["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.
Comment