<?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['m'])&& $_POST['m'] !=""){
	$p = 0; 
	$m = ($_POST['m']+100)/100;
}
else{ 	
	$p = 0; 
	$m = 1;
}

echo '<table><tr><td height="100">';
echo '<form method="post" action="">';
echo 'Masukan M : <input type="text" name="m" 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 = $p+$m*( $r-$p); if($rr>255){$rr=255;} if($rr<0){$rr=0;}
$gg = $p+$m*( $g-$p); if($gg>255){$gg=255;} if($gg<0){$gg=0;}
$bb = $p+$m*( $b-$p);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);
include 'hasil.php';
?>
