Skip to main content
Participant
April 21, 2022
Question

Can CF write exif meta data?

  • April 21, 2022
  • 2 replies
  • 493 views

Hi, guys...

I've found imageGetExifMetadata for extraction.

Now, I'm trying to figure out how to edit an image's meta data.

Can CF do that, itself?

If not, anyone have a solution?

Thanks for any assistance!

Rick

    This topic has been closed for replies.

    2 replies

    James Moberg
    Inspiring
    April 23, 2022

    I've written a IPTC CFC to do this for professional photographers that we've developed web applications for. The script uses ExifTool.  I've searched other methods, but nothing matches ExifTool in terms of metatags support and performance.  (We did this so results in Google Photo search would display their copyright data. It's better to have the data embedded within each image rather than contained in a separate HTML-based XML tag on a webpage.)

    Please note that when you update JPG metadata, you'll need to update multiple fields because different programs look in different areas.  For instance, when updating "Credit", we update the following metadata using ExifTool:

    • By-Line
    • Creator
    • Credit
    • Artist
    • XMP-photoshop:Credit

     

     

    Community Expert
    April 26, 2022

    That is a great answer.

     

    Dave Watts, Eidolon LLC

    Dave Watts, Eidolon LLC
    Community Expert
    April 22, 2022

    I don't think CF will let you do that directly.* But there is an Apache Commons project that will let you do that, in theory:

     

    https://commons.apache.org/proper/commons-imaging/

     

    There are also plenty of command-line tools that will manipulate EXIF data. I use one called, uh, exiftool.exe. You can automate this with CFEXECUTE, probably.

     

    * note: CF may use the previous version of Apache Commons, Sanselan, to support imageGetExifMetadata already. I saw a forum post that mentioned it briefly, I think. I'd probably go with exiftool.exe actually, now that I think about it.

     

    Dave Watts, Eidolon LLC

     

     

    Dave Watts, Eidolon LLC
    BKBK
    Community Expert
    Community Expert
    April 23, 2022

    Like Dave, I don't think ColdFusion has any functionality to directly edit image metadata. I would go for Dave's second recommendation, ExifTool. You could, for example, run the Windows Executable ExifTool using ColdFusion's cfexecute.

     

    ExifTool is Open Source and is extensively documented. See, in particular, the ExifTool Writing Examples.

     

    Now, some proof of the pudding.

     

    I gave it a go as follows:

    1.  Download the Windows executable to C:\bin\Exif tool for images\exiftool-12.41\exiftool.exe;
    2.  Place a test image at C:\ColdFusion2021\cfusion\images\dir\testImage.jpg;
    3. Get the current image metadata, using
      <cfscript>
      img=imagenew("C:\ColdFusion2021\cfusion\images\dir\testImage.jpg");
      
      // Store the exif metadata as an HTML in the logs directory
      writedump(var=imagegetexifmetadata(img), format="html", output="#server.coldfusion.rootdir#\logs\testImageExif.html");
      
      writeoutput("done");
      </cfscript>
      ​

       

    4.  Use exiftool to add 1.5 hours to every date in the metadata of the test image
      <cfexecute name="C:\bin\Exif tool for images\exiftool-12.41\exiftool.exe" arguments=" -AllDates+=1:30 C:\ColdFusion2021\cfusion\images\dir\testImage.jpg" />
      done​
    5. (The Exiftool command does 2 things: creates a back-up of the original image file, plus a new image file having the updated metadata) Rerun the code in step 3 to get the metadata of the new file, and confirm that all the dates have indeed been increased by 1.5 hours.