Friday, February 19, 2010

How to Add a Timestamp to Photos after they've been downloaded

Newer digital cameras aren't supporting embeding a timestamp in the photo. However our Regualtory services people require this feature for Legal reasons.

The following procedure can be used to add a Visual Timestamp to an image;

Install IrfanView
Install IrfanView plugins on the same page

  1. Load Iview
  2. Click file
  3. Click batch conversion/rename
  4. Add files that need to be stamped
  5. check on Use advanced options
  6. click set advanced options
  7. check on Add Overlay text
  8. click settings
  9. Make sure we've set text box Width 3648 height 2736
  10. Enter the EXIF TAG Value of the Date Taken TAG ( $E36867)
  11. Set the font to something inteligent (Calibri 48 Bold Green)
  12. Click OK
  13. Click Ok
  14. Click Start


Happy days. If legal boffins decide to challenge the validity of the timestaps we can provide them with the original files and they can check the date tags themselves.

UPDATE 14/05/2013 - Saw this is by far the most visited blog post I've made. So cleaned it up and removed referenced to user permissions this post assumes you have admin rights.

5 comments:

  1. Thought I'd stick my oar to say that this task can also be automated/batched with PowerShell, without any 3rd party tools. Just run the function below in PowerShell, then pass the function an array of file objects...

    Example:
    PS C:> Get-ChildItem "C:\Users\Chris\Desktop\test\*" -include *.jpg | Foreach-Object{Add-EXIFDataToImage $_}

    ###############################

    function Add-EXIFDataToImage {

    param($image)

    add-type -AssemblyName system.drawing

    function Get-EXIFData {

    param($filePath)

    $imageEXIF = New-Object -TypeName system.drawing.bitmap($filepath)
    [byte[]]$bytes = $imageEXIF.Getpropertyitem(36867).value
    if ($bytes.count -gt 0){
    $ASCIIEnc = [System.Text.Encoding]::ASCII
    $DateTimeString = $ASCIIenc.GetString($bytes)
    $arrDateTime = $DateTimeString.split(" ")
    return [datetime]"$($arrDateTime[0].replace(":","-")) $($arrDateTime[1])"
    }
    else
    {write-host "$filePath contained no 'DateTaken' information"}
    }


    function Add-DatetoImage {

    param(
    $fileName,
    $string
    )

    $parent=split-path $_.fullname
    $newFileName = join-path -Path $parent -ChildPath "$($_.basename)_new$($_.extension)"

    $objImage = [system.drawing.image]::FromFile($fileName)
    $objCanvas = [system.drawing.Graphics]::FromImage($objImage)
    $objImage.SetResolution(72,72)
    [single]$DesiredWidth = $($objImage.Width) * .25
    $objFont = new-object system.drawing.font([system.drawing.fontfamily]"Verdana",12,[system.drawing.fontstyle]"Bold")
    $StringSizeF = $objcanvas.MeasureString($string, $objFont)
    [single]$ratio = $StringSizeF.Width / $objFont.SizeInPoints
    $requiredFontSize = $DesiredWidth / $ratio

    $objFont = new-object system.drawing.font([system.drawing.fontfamily]"Verdana", $requiredFontSize,[system.drawing.fontstyle]"Bold")
    $objBrush = new-object system.drawing.SolidBrush([system.Drawing.Color]::FromArgb(128, 255, 0, 0))
    $objcanvas.DrawString($string,$objFont,$objBrush,0,0)

    $objImage.Save($newfileName)

    }

    $DateTaken = Get-EXIFData $image.fullname
    Add-DateToImage $image.fullname $DateTaken

    }

    ReplyDelete
  2. That's a great call Chris.

    So thinking about that... Could we watch a folder for new images and then run that script on them?

    ReplyDelete
  3. Ben, this doesn't work for me.
    It creates a copy of the photo wherever I tell it to, but it doesn't make any change to the photo...I tried a million variations of this and nothing worked.

    ReplyDelete
    Replies
    1. Sorry to hear that. Is it possible that the images you are working on have no data in the EXIF TAG?

      This guy seems to have an EXIF TAG viewer http://regex.info/exif.cgi

      Let us know if this shows you anything in the time stamp fields.

      Delete
  4. I'm also using this method to insert the date/time to screenshots I've taken. As it's normally just one photo at a time, I use the add text feature instead of batch processing.

    1/. Draw a box on the image where you want the text
    2/. Hit CTRL+T to open the text edit box
    3/. For Date/Time of the file, add $T in the 'text' box or use the code above for EXIF data.
    4/. CTRL+S to Save

    ReplyDelete