我对通过移动相机拍摄的图像有一些问题,然后上传到我的服务器。该功能可以正常工作,没有问题,但取决于相机如何面对图像以尴尬的方式出现。我想要它做的就是让图像以正确的方式进行。我附上了一张图片给你举了一个例子,左边是它现在是如何工作的,右边是我想要它的工作方式。有什么想法吗?
图片示例
PHP - ak_php_img_lib_1.0
<?php
// Function for resizing jpg, gif, or png image files
function ak_img_resize($target, $newcopy, $w, $h, $ext) {
list($w_orig, $h_orig) = getimagesize($target);
$scale_ratio = $w_orig / $h_orig;
if (($w / $h) > $scale_ratio) {
$w = $h * $scale_ratio;
} else {
$h = $w / $scale_ratio;
}
$img = "";
$ext = strtolower($ext);
if ($ext == "gif"){
$img = imagecreatefromgif($target);
} else if($ext =="png"){
$img = imagecreatefrompng($target);
} else {
$img = imagecreatefromjpeg($target);
}
$tci = imagecreatetruecolor($w, $h);
// imagecopyresampled(dst_img, src_img, dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h)
imagecopyresampled($tci, $img, 0, 0, 0, 0, $w, $h, $w_orig, $h_orig);
imagejpeg($tci, $newcopy, 80);
}
?>
PHP - AttachImage
if(isset($_FILES['UploadFileField'])){
$allowed = array('jpg','png');
$name = $_FILES["UploadFileField"]["name"];
$tmp = $_FILES['UploadFileField']['tmp_name'];
$type = $_FILES['UploadFileField']['type'];
$newName = "Image Attachment.jpg";
$types = array('jpg','png');
$ext = pathinfo($name, PATHINFO_EXTENSION);
if(in_array($ext,$types)){
move_uploaded_file($tmp, "UPLOADS/$newName");
echo '<font size="3"><p align="center"><b>UPLOAD SUCCESSFUL: </font><font color="#000000" size="3">Your document has now been uploaded and is ready to send.</b></p></font>';
include_once("ak_php_img_lib_1.0.php");
$target_file = "UPLOADS/$newName";
$resized_file = "UPLOADS/resized_$newName";
$wmax = 200;
$hmax = 200;
ak_img_resize($target_file, $resized_file, $wmax, $hmax, $ext);
}
else {
if(!$tmp){
echo '<font size="3"><p align="center"><b>UPLOAD FAILED: </font><font color="#000000" size="3">No document has been selected.</b></p></font>';
}
else {
echo '<font size="3"><p align="center"><b>UPLOAD FAILED: </font><font color="#000000" size="3">Uploaded document was an incorrect extension type, please use ".jpg" or ".png" only.</b></p></font>';
}
}
}
if (isset($_POST['submit'])){
header( 'Location: Review.php' );
}
if (isset($_POST['delete'])){
if (file_exists("UPLOADS/Image Attachment.jpg")) {
echo '<font size="3"><p align="center"><b>DETLEION COMPLETE: </font><font color="#000000" size="3">Image no longer available</b></p></font>';
unlink('UPLOADS/Image Attachment.jpg');
unlink('UPLOADS/resized_Image Attachment.jpg');
}
else{
echo '<font size="3"><p align="center"><b>DETLEION FAILED: </font><font color="#000000" size="3">No image available for Deletion</b></p></font>';
}
}
HTML - AttachImage
<body link="black">
<div class="gridContainer clearfix">
<div id="borderDiv">
<div id="navDiv">
<div id="backNavDiv">
<a href="index.php?logout"><font color="white"><p align="right"><b> < Log Out</b></p></font></a>
</div>
</div>
<div id="headerDiv">
<p>Attach Image</p>
</div>
<?php
if (file_exists("UPLOADS/resized_Image Attachment.jpg")) {
echo '<div class="uploadImage"></div>';
}
else{
echo '<div class="loadingImage"></div>';
}
?>
<div id="loginBtnDiv">
<div id="uploadAreaDiv">
<form action="AttachImage.php" method="post" enctype="multipart/form-data" name="FileUploadForm" id="FileUploadForm">
<label for="UploadFileField"></label>
<input type="file" name="UploadFileField" id="UploadFileField"/>
<input type="submit" name="UploadButton" id="UploadButton" value="Upload"/>
</form>
</div>
<form action="AttachImage.php" method="post" enctype="multipart/form-data" name="delete" id="delete">
<input id="delete" name="delete" type="submit" value="Delete">
</form>
<form action="AttachImage.php" method="post" enctype="multipart/form-data" name="FileForm" id="FileForm">
<input id="submit" name="submit" type="submit" value="Next">
</form>
</div>
</div>
</div>
<div id="logoDiv">
<img src="IMAGES/Logo.png">
</div>
</body>
CSS - 大师
.uploadImage {
background: url(../UPLOADS/resized_Image%20Attachment.jpg) 50% 50% no-repeat;
width: 200px;
height: 200px;
margin-left: auto;
margin-right: auto;
}
.loadingImage {
background: url(../IMAGES/loading.gif) 50% 50% no-repeat;
width: 200px;
height: 200px;
margin-left: auto;
margin-right: auto;
}