ios – Why imgur adds white background to some png images, and to others not with Alamofire and Swift?


This is how i simply upload images to Imgur using Alamofire and Swift:

let url = URL(string: "https://api.imgur.com/3/upload")!
private var headers: [String: String] {
    ["X-Token": "[mytokenhere]", "Authorization": "Client-ID [myidhere]"]
}

Alamofire.upload(multipartFormData: { multipart in
    if let data = UIImagePNGRepresentation(image.image) {
         multipart.append(data, withName: "image", fileName: "image.png", mimeType: "image/png")
    }
}, to: url, headers: headers, encodingCompletion: { result in
    //convert result image from result here
})

Example before upload, original image (as you can see, it adds white background even here on SO, why?):

enter image description here

and after upload, returned url to an uploaded image:

enter image description here

originally on computer and iphone it look like this:

enter image description here

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img