Jump to content

change date taken (file property) from an image


gcue
 Share

Recommended Posts

Hello World!

I have looked across the internet on how to change date taken and have only found how to GET date taken.  I couldnt figure out how to CHANGE it nor could i find an example.

this is the closest I got but script didnt make sense as I didnt really see a class being referenced.

http://www.experts-exchange.com/questions/23868806/Looking-for-a-VB-solution-to-change-jpg-Date-Taken-attribute.html

this also seemed promising

https://technet.microsoft.com/en-us/magazine/2008.03.heyscriptingguy.aspx?pr=PuzzleAnswer

this is how i am getting Date Taken (thanks Melba!)

Any help is greatly appreciated!

Edited by gcue
Link to comment
Share on other sites

  • 3 weeks later...

i am still trying to figure out how to do this.  for now i am resorting to FileAdding a command line tool (ExifTool.exe) but its 5MB!  There are other command line tools out there but this one supports more file formats

im sure there has to be someone else who has accomplished this via autoit!

many thanks in advance!

Link to comment
Share on other sites

looks promising!!!!  thank youuuu

any idea what i need to do with this error?  i tried declaring it at the top of the script but doesnt seem to work - no file gets created

error: $ghGDIPDll: undeclared global variable.
    $aResult = DllCall($ghGDIPDll,

Link to comment
Share on other sites

sure thing

#include <array.au3>
#include <GDIPlus.au3>
#include <file.au3>

$msg_normal = 0

Global Const $PropertyTagTypeByte = 1
Global Const $PropertyTagTypeASCII = 2
Global Const $PropertyTagTypeShort = 3
Global Const $PropertyTagTypeLong = 4
Global Const $PropertyTagTypeRational = 5
Global Const $PropertyTagTypeUndefined = 7
Global Const $PropertyTagTypeSLong = 9
Global Const $PropertyTagTypeSRational = 10

_GDIPlus_Startup()


$dir = "C:\Users\Me\Desktop\Halloween"
$date_time = "2015:10:29 09:00:00"

$array = _FileListToArrayRec($dir, "*.jpg", $FLTAR_FILES, 1, $FLTAR_SORT, $FLTAR_FULLPATH)

For $x = 1 To UBound($array) - 1
    $original_file = $array[$x]

    $file_name_extension = StringRegExpReplace($original_file, "^.*\\", "")
    $file_path_dir = StringReplace($original_file, "\" & $file_name_extension, "")
    $file_name = _GetFileName($original_file)
    $file_extension = _GetFileExtension($file_name_extension)

    $temp_file = $file_path_dir & "\" & $file_name & "_TMP." & $file_extension

    $hFile = _GDIPlus_ImageLoadFromFile($original_file)

    _GDIPlus_SetMetaData($hFile, "DateTimeOriginal", $date_time)

    _GDIPlus_ImageSaveToFile($hFile, $temp_file)

    _GDIPlus_ImageDispose($hFile)

    FileMove($temp_file, $original_file, 1)
Next

_GDIPlus_Shutdown()

Func _GDIPlus_SetMetaData($hHandle, $sTagName, $vStr)

    Local $tagPropertyItem = "ulong id; ulong length; ushort Type; ptr value"
    Local $Struct_String, $Struct_Meta, $aResult, $PropertyTagType

    Switch $sTagName
        Case "ImageWidth"
            $ID = 0x100
            $PropertyTagType = $PropertyTagTypeShort

        Case "ImageLength"
            $ID = 0x101
            $PropertyTagType = $PropertyTagTypeShort

        Case "BitsPerSample"
            $ID = 0x102
            $PropertyTagType = $PropertyTagTypeShort

        Case "Compression"
            $ID = 0x103
            $PropertyTagType = $PropertyTagTypeShort

        Case "PhotometricInterpretation"
            $ID = 0x106
            $PropertyTagType = $PropertyTagTypeShort

        Case "Orientation"
            $ID = 0x112
            $PropertyTagType = $PropertyTagTypeShort

        Case "SamplesPerPixel"
            $ID = 0x115
            $PropertyTagType = $PropertyTagTypeShort

        Case "PlanarConfiguration"
            $ID = 0x11C
            $PropertyTagType = $PropertyTagTypeShort

        Case "YCbCrSubSampling"
            $ID = 0x212
            $PropertyTagType = $PropertyTagTypeShort

        Case "YCbCrPositioning"
            $ID = 0x213
            $PropertyTagType = $PropertyTagTypeShort

        Case "XResolution"
            $ID = 0x11A
            $PropertyTagType = $PropertyTagTypeRational

        Case "YResolution"
            $ID = 0x11B
            $PropertyTagType = $PropertyTagTypeRational

        Case "ResolutionUnit"
            $ID = 0x296
            $PropertyTagType = $PropertyTagTypeShort

        Case "StripOffsets"
            $ID = 0x111
            $PropertyTagType = $PropertyTagTypeShort

        Case "RowsPerStrip"
            $ID = 0x116
            $PropertyTagType = $PropertyTagTypeShort

        Case "StripByteCounts"
            $ID = 0x117
            $PropertyTagType = $PropertyTagTypeShort

        Case "JPEGInterchangeFormat"
            $ID = 0x201
            $PropertyTagType = $PropertyTagTypeLong

        Case "JPEGInterchangeFormatLength"
            $ID = 0x202
            $PropertyTagType = $PropertyTagTypeLong

        Case "TransferFunction"
            $ID = 0x12D
            $PropertyTagType = $PropertyTagTypeShort

        Case "WhitePoint"
            $ID = 0x13E
            $PropertyTagType = $PropertyTagTypeRational

        Case "PrimaryChromaticities"
            $ID = 0x13F
            $PropertyTagType = $PropertyTagTypeRational

        Case "YCbCrCoefficients"
            $ID = 0x211
            $PropertyTagType = $PropertyTagTypeRational


        Case "ReferenceBlackWhite"
            $ID = 0x214
            $PropertyTagType = $PropertyTagTypeRational

        Case "DateTimeOriginal"
            $ID = 0x9003
            $PropertyTagType = $PropertyTagTypeASCII

        Case "DateTime"
            $ID = 0x132
            $PropertyTagType = $PropertyTagTypeASCII

        Case "ImageDescription"
            $ID = 0x10E
            $PropertyTagType = $PropertyTagTypeASCII

        Case "Make"
            $ID = 0x10F
            $PropertyTagType = $PropertyTagTypeASCII

        Case "Model"
            $ID = 0x110
            $PropertyTagType = $PropertyTagTypeASCII

        Case "Software"
            $ID = 0x131
            $PropertyTagType = $PropertyTagTypeASCII

        Case "Artist", "Author"
            $ID = 0x13B
            $PropertyTagType = $PropertyTagTypeASCII

        Case "Copyright"
            $ID = 0x8298
            $PropertyTagType = $PropertyTagTypeASCII

        Case Else
            Return SetError(1, -1, False)
    EndSwitch

    ; Store string in array
    $Struct_String = DllStructCreate("char[" & StringLen($vStr) + 1 & "];")
    DllStructSetData($Struct_String, 1, $vStr)

    $Struct_Meta = DllStructCreate($tagPropertyItem)
    DllStructSetData($Struct_Meta, "ID", $ID)
    DllStructSetData($Struct_Meta, "Length", StringLen($vStr) + 1)
    DllStructSetData($Struct_Meta, "Type", $PropertyTagType)
    DllStructSetData($Struct_Meta, "Value", DllStructGetPtr($Struct_String))

    $aResult = DllCall($__g_hGDIPDll, "int", "GdipSetPropertyItem", "hwnd", $hHandle, "ptr", DllStructGetPtr($Struct_Meta))
    If @error Then Return SetError(@error, @extended, False)

    Return SetError($aResult[0], 0, $aResult[0] = 0)

EndFunc   ;==>_GDIPlus_SetMetaData

Func _GetFileName($sFile)

    $file_name_extension = StringRegExpReplace($sFile, "^.*\\", "")
    $file_extension = StringRegExpReplace($file_name_extension, "^.*\.", "")
    $file_name = StringReplace($file_name_extension, "." & $file_extension, "")

    Return $file_name

EndFunc   ;==>_GetFileName

Func _GetFileExtension($sFile)
    Return StringRegExpReplace($sFile, "^.*\.", "")
EndFunc   ;==>_GetFileExtension

Func Debug($variable1 = "", $variable2 = "", $variable3 = "", $variable4 = "")

;~  #include <array.au3>
;~  $msg_normal = 0

    If IsArray($variable1) Then
        _ArrayDisplay($variable1)
    Else
        If $variable2 <> "" Then
            $variable1 &= @CRLF & $variable2
        EndIf

        If $variable3 <> "" Then
            $variable1 &= @CRLF & $variable3
        EndIf

        If $variable4 <> "" Then
            $variable1 &= @CRLF & $variable4
        EndIf

        ClipPut($variable1)
        MsgBox($msg_normal, "Debug", $variable1)
    EndIf

EndFunc   ;==>Debug

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...