Orientation Issue with iOS Image Upload

Initially, there was an issue with some photos that are uploaded on website and uploaded photos rotated (left, right or vertically) automatically.

Before Upload   After Upload


Later we found the actual issue and there is an issue with photos capture on iPhone by rotating phone and that are rotated after uploads.

Here photos taken on apple device and it adds the orientation rules to EXIF metadata of image. So based on that info you can correct the rotated photo. Here we correct photo orientation using below lucee code.


Error when loading gists from https://gist.github.com/.

<cfset var oImage1 = ImageNew(imgFilePath)>
<cfset var oImage2 = imageNew(ImageGetBufferedImage(oImage1))>

<cfset var imgEXIFinfo = ImageGetEXIFMetadata(oImage2)>
<cfif isStruct(imgEXIFinfo) AND structKeyExists(imgEXIFinfo,"Orientation")>
    <cfset var angleValue = "">
    <cfset var angleRegEx = "\(Rotate ([\d]+)">
    <cfset var arrMatched = REmatchNoCase(angleRegEx,imgEXIFinfo.Orientation)>
    <cfif arrayLen(arrMatched) eq 1>
        <cfset angleValue = reReplaceNoCase(arrMatched[1],angleRegEx,"\1")>
    <cfif isNumeric(angleValue)>
        <cfset imageRotate(name = oImage2, x = 0, y = 0, angle = angleValue, interpolation = "bicubic")>
        <cfset imageWrite(oImage2,imgEXIFinfo.source,1)>

So using the orientation angel value we can rotate the image and we get image in correct orientation. 

Hope this my experience help you.