Leave That Thing Alone Blog

Using Exif Orientation to Rotate Digital Photos with ColdFusion

Here's a ColdFusion 8 function to rotate digital photographs via Exif 'orientation'. This function will accept a cfimage or a filename and return a rotated/flipped (if needed) image in cfimage format.

With ColdFusion 8's 'ImageGetEXIFMetadata' tag you can get the 'orientation' of a digital photograph. The 'orientation' value indicates if the camera was held/rotated landscape, upside down, portrait with right on the top, etc.

What makes this a bit more difficult is that there are 8 different orientation possibilities and the 'orientation' value can be a number or comma separated text. For example value 1== 'top, left side'. Full exif 'orientation' details here.


Example usages of imageExifOrientationRotate:


<!--- specify image via filename --->
<cfset myImage = imageExifOrientationRotate('IMG_3087.jpg') />
<!--- resize --->
<cfset imageResize(myImage,"200","") />
<!--- display --->
<cfimage action="writeToBrowser" source="#myImage#" />

or


<!--- read image --->
<cfimage action="read" source="IMG_3087.jpg" name="myImage" />
<!--- specify image via cfimage --->
<cfset myImage = imageExifOrientationRotate(myImage) />
<!--- resize --->
<cfset imageResize(myImage,"200","") />
<!--- display --->
<cfimage action="writeToBrowser" source="#myImage#" />

View imageExifOrientationRotate function:

Related Blog Entries

Comments

Emmet McGovern's Gravatar Nice function. This problem showed itself to me recently. If you take an exif rotated photo and process with cfimage then it shows normally as landscape in a browser, if you view it in iphone safari then the exif data is used and the photo is rotated breaking your layout possibly.
# Posted By Emmet McGovern | 11/20/09 3:14 PM
coldfusioner's Gravatar Thanks for the code!
But there is a flaw in imageRotate function. Use
imageRotate(arguments.image,0,0,rotateDegrees,arguments.interpolation);
# Posted By coldfusioner | 10/14/12 8:53 AM