[英]Swift capture photo in portrait mode and upload to server - The uploaded image appears in wrong orientation
如果我使用iPhone以人像模式拍攝照片,然后使用alamofire將其發送到服務器->圖像將被完美存儲。 如果我嘗試在html中使用此圖片,則方向錯誤。 圖像旋轉-90度。 我試圖將圖像保存為jpg和png格式,但是兩者都存在相同的問題。
Alamofire.upload(
multipartFormData: { multipartFormData in
multipartFormData.append(imageData, withName: "image", fileName: "image.png", mimeType: "image/png")
},
to: SERVER_URL,
encodingCompletion: { encodingResult in
switch encodingResult {.....
在服務器端:
<?php
.....
$response['error'] = "NULL";
$filename = uniqid() . ".png";
move_uploaded_file($_FILES['image']['tmp_name'], "image/" . $filename) ......
?>
我認為會有2種不同的解決方案,但我找不到正確的方法。 1)我必須以某種方式更改iPhone設備上的方向2)在上傳到服務器之前,必須更改服務器端的方向。
(我不想在客戶端上提供解決方案)
您可以使用imageOrientation
屬性獲取UIImage
方向,並將其作為參數傳遞給服務器端,然后決定在后端做什么。
您還可以使用以下代碼更改圖像方向:
let pngImage = #imageLiteral(resourceName: "yourImageFileName")
let image = UIImage(cgImage: pngImage.cgImage, scale: pngImage.scale, orientation: UIImage.Orientation.up)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.