【问题标题】:Swift capture photo in portrait mode and upload to server - The uploaded image appears in wrong orientation快速以纵向模式拍摄照片并上传到服务器 - 上传的图像显示方向错误
【发布时间】:2019-03-02 14:46:36
【问题描述】:

如果我用我的 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) ...... 
 ?>

我认为会有两种不同的解决方案,但我找不到正确的方法。 1)我必须以某种方式改变我的 iPhone 设备上的方向 2) 在上传到服务器之前,我必须在服务器端更改方向。

(我不想在客户端做解决方案)

【问题讨论】:

  • 我想制作一个纵向模式的头像。

标签: php html swift image alamofire


【解决方案1】:

您可以使用imageOrientation 属性获取UIImage 方向并将其作为参数传递给服务器端,然后决定在后端做什么。

您还可以使用以下代码更改图像方向:

let pngImage = #imageLiteral(resourceName: "yourImageFileName")
let image = UIImage(cgImage: pngImage.cgImage, scale: pngImage.scale,   orientation: UIImage.Orientation.up)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-04
    • 2021-12-09
    • 2020-02-08
    • 2013-10-28
    • 1970-01-01
    • 2013-10-03
    • 2014-08-12
    • 1970-01-01
    相关资源
    最近更新 更多