<?php
session_start();
?>
<form enctype="multipart/form-data" action="" method="POST">
Отправить этот файл: <input name="userfile" type="file" />
<input type="submit" name="sbutton" value="Отправить файл" />
<select name="selectvar">
<option>оттенки серого</option>
<option>яркость</option>
</select>
</form>
<?php
if ($_POST['sbutton']){
$uploaddir = 'files/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
$uploadfile2 = $uploaddir ."hello".basename($_FILES['userfile']['name']);
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))
echo "Файл корректен и был успешно загружен.\n";
echo "<br>";
$_SESSION['choice'] = 0;
$_SESSION['fname'] = $uploadfile;
$_SESSION['fname2'] = $uploadfile2;
}
if (strcmp($_POST['selectvar'], "оттенки серого") == 0) {
$_SESSION['choice'] = 1;
$str_1 = <<<EOD1
<form method="post" enctype="multipart/form-data">
<br>
EOD1;
$str_2 = <<<EOD2
<br>
<br>
<input type="range" value="0" name="arg1" min="0" max="256" onchange="document.getElementById('textInput1').value=this.value;">
<br>
<input type="text" id="textInput1" value="0">
<br>
<input type="range" value="0" name="arg2" min="0" max="256" onchange="document.getElementById('textInput2').value=this.value;">
<br>
<input type="text" id="textInput2" value="0">
<br>
<input type="range" value="0" name="arg3" min="0" max="256" onchange="document.getElementById('textInput3').value=this.value;">
<br>
<input type="text" id="textInput3" value="0">
<br>
<input type="submit" name="grayscalebutton" value="оттенки серого"><br>
</form>
EOD2;
}
if (strcmp($_POST['selectvar'], "яркость") == 0) {
$_SESSION['choice'] = 2;
$str_1 = <<<EOD1
<form method="post" enctype="multipart/form-data">
<br>
EOD1;
$str_2 = <<<EOD2
<br>
<br>
<input type="range" value="0" name="arg1" min="-255" max="255" onchange="document.getElementById('textInput1').value=this.value;">
<br>
<input type="text" id="textInput1" value="0">
<br>
<input type="submit" name="grayscalebutton" value="яркость"><br>
</form>
EOD2;
}
echo $str_1;
echo "<img src={$_SESSION['fname']} >";
echo "<img src={$_SESSION['fname2']} >";
echo $str_2;
if (isset($_SESSION['fname']) && $_SESSION['choice'] == 1)
{
$image = imagecreatefrompng($_SESSION['fname']);
imagesavealpha($image, true);
imagefilter($image, IMG_FILTER_COLORIZE, $_POST['arg1'],$_POST['arg2'],$_POST['arg3']);
imagepng($image, $_SESSION['fname2']);
}
if (isset($_SESSION['fname']) && $_SESSION['choice'] == 2)
{
$image = imagecreatefrompng($_SESSION['fname']);
imagesavealpha($image, true);
imagefilter($image, IMG_FILTER_BRIGHTNESS, $_POST['arg1']);
imagepng($image, $_SESSION['fname2']);
}
?>
|