Resized images uploaded seem to rotate when they are resized. It seems to rotate image taken with the camera directly uploaded from a WebView 90 CCW. Images uploaded from the camera roll seem to rotate 180.
return try req.content.decode(UserFile.self).map(to: Response.self) { data in
// create an array of the file types we're willing to accept
let acceptableTypes = [MediaType.png, MediaType.jpeg]
for file in data.upload {
// ensure this image is one of the valid types
guard let mimeType = file.contentType else { continue }
guard acceptableTypes.contains(mimeType) else { continue }
// replace any spaces in filenames with a dash
/let cleanedFilename = file.filename.replacingOccurrences(of: " ", with: "-")
// convert that into a URL we can write to
let newURL = originalsDirectory.appendingPathComponent(cleanedFilename)
// write the full-size original image
_ = try? file.data.write(to: newURL)
// create a matching URL in the thumbnails directory
let thumbURL = thumbsDirectory.appendingPathComponent(cleanedFilename)
// attempt to load the original into a SwiftGD image
if let image = Image(url: newURL) {
// attempt to resize that down to a thumbnail
if let resized = image.resizedTo(width: 300) {
// it worked – save it!
resized.write(to: thumbURL)
var tags = [String]()
if data.tag_line != nil {
tags.append(data.tag_line!)
}
let p = //Create a Photo object to save
p.save(on: req)
}
}
}
return req.redirect(to: "upload")
}
Resized images uploaded seem to rotate when they are resized. It seems to rotate image taken with the camera directly uploaded from a WebView 90 CCW. Images uploaded from the camera roll seem to rotate 180.