Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Correction of rotation of pictures coldfusion

Posted on 2015-01-03
2
352 Views
Last Modified: 2015-01-09
Portrait pictures get rotated?

http://www.housecarers.com/photo_view2.cfm?mem=2145674015&slide=6

So this is an example of the same page where the image is ok - for another client.
It does not happen for most images posted by clients  - just some

http://www.housecarers.com/photo_view2.cfm?mem=2145661960&slide=4

Please how do I Prevent this? - display without rotation, or rotate back to normal
I just want the picture to display as is.


When I look at the original it is OK see below - it is portrait - see here:
http://housecarers.com/pics/2145674015_6.jpg?ref=%227842%22

I am told I will need a coldfusion server solution, the reason only some images appear flipped is becuase
the cameras are different. this is meta data set by the camera - nothing to do with CSS.

I am on CF10

I am also told while I can do rotation client side,
I would need to wait until the image is loaded to get the exif_data to determine whether
 to rotate or not. imo, lots of unnecessary work that's better left to the server

<IMG ID="DataField40" SRC="/pics/2145674015_6.jpg?ref=4096"  
ALT="House Sitters Pictures from YouthfulRetiree">

Open in new window

0
Comment
Question by:Ian White
2 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 40532170
Edit: Added more detail


Please how do I Prevent this? - display without rotation, or rotate back to normal I just want the picture to display as is.

If I'm not mistaken, I think that IS the actual angle of the image, and the EXIF orientation tells capable devices how to rotate it.  If so, you'd need to apply any orientation shift to the image object.

To do it server side, the basic process would be:

1) read the orientation from the metadata.
2) use the returned orientation to rotate the image to the correct position
3) Fix (or remove) the orientation value in the metadata. (Otherwise, the browser will continue to rotate the image).
4) Save the "fixed" image to disk.

Unfortunately .. CF doesn't have much in the way of native EXIF functionality.  It only supports "reading" metadata. AFAIK there are no functions for modifying or saving metadata.

If you don't need to preserve the metadata, the simplest option is to manipulate the image and save the fixed image to disk. ImageWrite erases all metadata, so once you save a new copy of the image, the "orientation" value won't be an issue anymore. Note - since image functions are very process intensive, only do this once, when the image is uploaded/added.

For example, using the image above:

<cfset origImage = imageRead(ExpandPath("2145674015_6.jpg"))>
<!--- get orientation from metadata --->
<cfset orientation = ImageGetEXIFTag(origImage,"orientation")>
<cfif orientation eq "Right side, top (Rotate 90 CW)">
	<cfset ImageRotate(origImage, 90)>
</cfif>
<!--- save it to disk WITHOUT the metadata --->
<cfset imageWrite(origImage, ExpandPath("newImage.jpg"))>


Fixed Image: <img src="newImage.jpg">

Open in new window



Of course you need to handle other orientations as well.  Unfortunately, CF seems to present a "human friendly" description instead of the standard orientation values used by most programs: ie orientation 1-8. I don't see a listing of possible values in the CF docs anywhere, so you may need to do some research on those. But the basic idea is the same. Get the orientation, rotate or flip the image accordingly.

If you need to preserve the EXIF metadata for some reason, try something like http://writeexif.riaforge.org/. I have not used it myself, but it may work.
0
 

Author Closing Comment

by:Ian White
ID: 40541480
Thanks - I think I will just give the users the option to rotate
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
iPhone looses session info 5 30
Coldfusion session variables in scheduled job 1 356
Comparing 2 Lists Coldfusion 8 55
coldfusion cfloop help 6 34
The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question