<?php
session_start();
if(!empty($_POST['simpan'])){
	header("location:wait.php");
	$tampung = imagecreatefromjpeg("gambar01cp.jpg");
	imagejpeg($tampung,"gambar01.jpg",100);
}
else if(!empty($_POST['cancel'])){ 
	header("location:wait.php");
} 
else if(isset($_POST['c'])&& $_POST['c'] !=""){ 
	$c = $_POST['c']; 
} 
else{ 
	$c = 0; 
}

echo '<table><tr><td height="100">';
echo '<form method="post" action="">';
echo 'Masukan C : <input type="text" name="c" value"0">';
echo '<input type="submit" name="submit" value="Submit" /><br/>';
//echo '<input type="submit" name="simpan" value="Simpan" />';
//echo '<input type="submit" name="cancel" value="Cancel" />';
echo '</form></td></tr></table>';

$asli = imagecreatefromjpeg("gambar01.jpg");
$lebar = imagesx($asli);
$tinggi = imagesy($asli);

$baru = imagecreatetruecolor($lebar, $tinggi);

for ($x = 0; $x < $lebar; $x++) {
for ($y = 0; $y < $tinggi; $y++) {

$pixelasli = imagecolorat($asli,$x,$y);
$cols = imagecolorsforindex($asli, $pixelasli);
  $r = $cols['red'];
  $g = $cols['green'];
  $b = $cols['blue'];

//tambahkan dengan constanta   
 $rr = $r + $c;  if ($rr > 255) { $rr = 255;} 
                 if ($rr < 0) { $rr = 0;}  
 $gg = $g + $c;  if ($gg > 255) { $gg = 255;} 
                 if ($gg < 0) { $gg = 0;} 
 $bb = $b + $c;  if ($bb > 255) { $bb = 255;} 
                 if ($bb < 0) { $bb = 0;}

$warna = imagecolorallocate($baru, $rr, $gg, $bb); 
imagesetpixel($baru, $x, $y, $warna);
}}

imagejpeg($baru,"gambar01cp.jpg",100);
//echo '<img src="gambar01cp.jpg" >';
include 'hasil.php';

?>


