Yesterday on Facebook I saw one of those "PLEASE SHARE WITH EVERYONE" type posts involving pictures and GPS data. Apparently there are still people who don't know about the metadata embedded with pictures and how they can be a risk. Fair enough - it's not like your camera typically warns you about this and if you don't know this stuff even exists, you can certainly understand how folks would be surprised when they found out. Given that you may want to help users out with this, how could you use ColdFusion to remove EXIF data from an image?
I thought this would be rather simple, but from what I can see, it is impossible. There is an imageGetEXIFMetadata function in ColdFusion, but no set or clear version. I did some Googling and discovered no solution at all. Brian Kresge blogged about this back in March, 2011 (EXIF Data, Coldfusion, and iPhones). His solution involved using imagePaste to copy the bits to a new image. I thought - surely - this can't be the only solution - but when I switched to Java I saw people doing something similar.
I hate to say it - but it looks like creating a new image is the only solution. This isn't terrible of course. If you are allowing folks to upload images you are probably doing work on them already - ensuring they aren't too big, possibly resizing them and creating thumbnails, etc. Here is a super simple example of this in action.
<cfset s = "/Users/ray/Desktop/ray.jpg">
<cfset img = imageRead(s)>
<cfset exif = imageGetExifMetadata(img)>
<cfdump var="#exif#" label="Exif Data">
<hr/>
<cfset sNew = "/Users/ray/Desktop/ray.clean.jpg">
<cfset imageWrite(img, sNew)>
<cfset img = imageRead(sNew)>
<cfset exif = imageGetExifMetadata(img)>
<cfdump var="#exif#" label="Exif Data">
I'd share a screen shot but all it shows is a big struct and then an empty struct. Keep in mind that if you want to preserve any of the EXIF data, you could. In my sample above I grab the data. You could store it in the database with the image file name. This could be useful data that you don't want to lose.
Archived Comments
What that scare post fails to tell you is that most responsible, legit social media sites do remove the metadata from the pictures you upload.
That's good to know. I never bothered to check if FB does it as I only use FB for friends anyway.
Still surprised there isn't an easy way to do this.
I've read up on it a bit in the past and there seems to be 2 distinct sides to the issue - one being privacy information advocates and the other being copyright advocates. I can see both sides of the issue so it's hard to say one way or another which makes the most sense.
I do agree though - you'd think there'd be an easy way.
I'd rather remove the EXIF data myself before submitting to another site than to rely and trust that someone else will do it for you. This mimics my beliefs in the workplace as I'm a proponent of the belief "If you want something done, you gotta do it yourself".
The masses currently consume and utilize media and other technology without having a true understanding of the best practices and security risks involved, and even though we, as IT professionals, can work to help them in any way possible, I still feel that empowering someone to be aware of a responsible for those actions is the best course.
Though many can (and will) claim the time-tested (yet illogical) adage of "I'm computer illiterate", the ultimate responsibility still lies with the person putting the photo up (rather than the site for scrubbing meta data).
FB strips out the geocoding right after uploading, which i find a PITA. it could simply figure out locations (down to some user-controlled level of detail) & *then* strip out that info.
in reference to the actual problem, have you looked at (used to be called sanselan)?
http://commons.apache.org/p...
we used older versions to write EXIF to JPEG images (geocoding) woks fine w/cf. the latest version has a method "removeExifMetadata" that strips out all EXIF data from an image.
you might also ping steve erat, i think he knows this EXIF stuff more than most.
@Paul: No, I had not. As I said, my Googling seemed to show no real solution (outside of reading in the bits and saving them as a new file as a way to nuke the EXIF). I'll have to try this.
The best tool for metadata handling is hands down ExifTool. It is a simple library (on Ubuntu you simply do a "apt-get install exiftool", has downloads for Windows and Mac too).
Then all you need to do is use some cfecexute-fu and you can read, write, modify any metadata of images, videos, audios and PDF's to your heart content.
We use it all over Razuna for many years with success.
http://www.sno.phy.queensu....
@Nitai: I'm really kinda opposed to a cfexecute solution... but not for any good reason. ;)
lol... I hear you.
Actually, we are writing everything to a .bat or .sh file and then only use cfexecute to execute those files. Then cfexecute only has to execute the file and not handle anything. Using this technique has saved us from many "issues" with cfexecute :-)
batch files & exe are kind of icky. but that thing has wrappers:
http://www.sno.phy.queensu....
under the "Programming" heading.
When do the Exif data actually get dropped? In the first write or in the second read?
Try this.
ImageRead() > Any Edit > imageWrite(). Go to image properties of the saved image (in windows) > details tab and you can still see the Exif data. ImageRead() or imageWrite() haven’t really drop Exif data yet.
Next do this:
Read > Edit > Write > Read > Write. Now if you go to details tab, Exif data is gone.
This looks rather like a bug to me, a ladybug perhaps, but nevertheless a bug.
That's not what I saw with my test - in the script above note it is just read and then write.
This isn't directly on topic, but it relates to reading/changing/deleting image metadata. When you right-click a JPEG file in Windows and go to Properties > Details, Windows will expose a variety of metadata. For example on a JPG file I scanned, under a sub-heading of Image, there are listed Dimensions, Width, Height, Horizontal Resolution, Vertical Resolution and Bit Depth. I initially assumed this was EXIF data, yet if I use imageGetExifMetadata(myImage), I get an empty structure. If I cfdump #myImage# I can see height and width, but no other metadata. I also tried using a couple different Exif/IPTC/XMP viewers/editors and those all come up empty. So my question is, if these values are not EXIF/IPTC/XMP metadata, what are they and is it possible to read them with Coldfusion? I'm particularly interested in the Resolution fields which are populated by the scanner software.
Thanks!
Well, for anyone who might also be interested, I solved my problem using Steven Erat's ImageMetadata.cfc (http://imagemetadata.riafor..., which is a simple Coldfusion cfc wrapper for the above mentioned ExifTool. By default, the CFC only parses the XMP namespaced tags, but adding in -exif:all into the cfexecute arguments brings in all the EXIF tags as well. And sure enough, all the values I am interested in are included in that EXIF data - even though several other EXIF readers, including CF's native tag, did not expose those values.
Thanks for sharing what worked for you, Eric!
EDIT: My original jpg files had no EXIF data whatsoever which is why all the other EXIF readers found nothing. Yet the values of height, width and resolution still show up in Windows. Once again, ExifTool to the rescue. A complete command-line dump of *all* metadata for the file (using -s to display the actual tag name and -g to group them by namespace) exposes File:ImageHeight, File:ImageWidth, JFIF:XResolution, and JFIF:YResolution. A little tinkering with Erat's CFC and - presto! - I can access these values via Coldfusion. Many thanks to Mr. Harvey, Mr. Erat and Mr. Camden for sharing your vast knowledge!