[請益] PHP GD 影像重複旋轉 會越來越大
現在我有放表單和顯示影像的form.html、二個處理用的A.php和B.php
form.html的板面這樣
--------------------
- 表單A - -
--------- 顯示影像 -
- 表單B - -
--------------------
A.php用來上傳jpg影像,並命名為test.jpg
B.php用來旋轉test.jpg影像
情形大概像這樣:
第一次開form.html
form.html A.php B.php
POST
表單A -------> 上傳影像
-
-
顯示影像(出現) <---header
-
- POST
表單B -----------------------------------------> 旋轉影像
-
-
顯示影像(旋轉過後的影像有出現,看起來是正常的) <------header
-
- POST
表單B -----------------------------------------> 旋轉影像
-
-
顯示影像(旋轉的影像黑底變大了= =...) <----------------header
第二次 第一次關掉後,在重開form.html
還沒上傳,顯示影像的部分就跑出來了QQ
要怎麼處理這兩個問題(紅色文字)呢~~
以下是程式碼:
form.html
<!doctype html>
<meta charset="utf-8">
<table border="1" cellspacing="0" cellpadding="10" style="width:100%"><tr>
<td>
<form action="A.php" method="post" enctype="multipart/form-data">
Please upload a JPG image:<br>
<input type="file" name="fileupload"><br>
<input type="submit" value="Upload">
</form>
</td>
<td rowspan="2" align="center" style="width:60%">
<img src="test.jpg">
</td>
</tr><tr>
<td>
<form action="B.php" method="post">
Rotate CCW angle(between 0 and 359 degrees):
<input type="number" name="degrees" min="0" max="359">
<input type="submit" value="Apply">
</form>
</td>
</tr></table>
A.php
<?php
if ( !in_array($_FILES["fileupload"]['type'],
array("image/jpeg","image/pjpeg")) )
{
header("Location: form.html");
}
else
{
if( $_FILES["fileupload"]["error"]==0 )
{
@file_put_contents("test.jpg",
file_get_contents($_FILES["fileupload"]["tmp_name"]));
header("Location: form.html");
}
}
?>
B.php
<?php
$filename = "test.jpg";
$degrees = $_POST["degrees"];
$source = imagecreatefromjpeg($filename);
$rotate = imagerotate($source, $degrees, 0);
imagejpeg($rotate, $filename);
imagedestroy($source);
imagedestroy($rotate);
header("Location: form.html")
?>
感恩QAQ
--
╭───────────────────╮
│ 我要努力, │
│ 跳出 我的 │ 框框
╰───────────────────╯
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.115.217.106
→
06/06 00:07, , 1F
06/06 00:07, 1F
→
06/06 00:07, , 2F
06/06 00:07, 2F
推
06/06 00:18, , 3F
06/06 00:18, 3F
→
06/06 00:21, , 4F
06/06 00:21, 4F
→
06/06 00:35, , 5F
06/06 00:35, 5F
→
06/06 00:35, , 6F
06/06 00:35, 6F
→
06/10 22:54, , 7F
06/10 22:54, 7F
→
06/10 22:55, , 8F
06/10 22:55, 8F
→
06/10 22:55, , 9F
06/10 22:55, 9F
※ 編輯: newton2009 來自: 140.115.217.106 (06/10 22:56)