NEF2JPG.vbs

Convert RAW images to jpg.
This script uses photoshop cs3 to convert raw nef files jpg images. A jpg directory will be created in the same directory where the raw images are. The jpg images will be saved with the same file name as the original raw image, however with a jpg extension instead of nef. The directory name is an argument on the command line. To start the script type:

cscript Nef2JPG.vbs c:\images
‘*****************************************************************
‘** Script: nef2jpg.vbs
‘** Version: 1.0
‘** Created: 12/29/2008 9:51PM
‘** Author: Adriaan Westra
‘** E-mail:
‘** Purpose / Comments:
‘** Process raw NEF files to jpg images
‘**
‘**
‘** Changelog :
‘** 29-12-2008 9:37 : Initial version
‘**
‘*****************************************************************

Dim Version : Version = “1.0” ‘ Script version
Dim Author : Author = “Adriaan Westra”
Dim Email : Email = “”
Dim appPhotoshop
Dim objImage
Dim strFileName

‘*****************************************************************
‘** Add Error Handling
on error resume Next

‘*****************************************************************
‘** Make sure the script is started with cscript
If InStr(wscript.FullName, “wscript.exe”) > 0 Then
MsgBox “Please run this script with cscript.exe.” & Chr(13) & _
“For example : cscript ” & WScript.ScriptName & ” /?”, _
vbExclamation, WScript.ScriptName
WScript.Quit(1)
End If

‘*****************************************************************
‘** Get commandline parameters
Set Args = Wscript.Arguments

If Args.Count = 0 Then
strImageDir = InputBox(“Please give the directory name ” & _
“to process : “,wscript.scriptname, strPath)
Else
If InStr(Args(0),”/?”) > 0 Or InStr(UCase(Args(0)),”/H”) > 0 _
Or InStr(UCase(Args(0)),”/HELP”) > 0 Then
DisplayHelp
Wscript.quit(0)
Else
strImageDir = Args(0)
End if
End if

‘*****************************************************************
‘** Get startup path from scriptfullname
Pos = InStr(wscript.ScriptFullName, wscript.ScriptName)
strPath = Mid(wscript.ScriptFullName,1,Pos – 1)
‘*****************************************************************
‘** Create output directory
strOutputDir = strImageDir & “\jpg”
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
If Not (objFSO.FolderExists(strOutputDir)) Then
Set objOutDir = objFSO.CreateFolder(strOutputDir)
End If

‘*****************************************************************
‘** Open Photoshop
Set appPhotoshop = CreateObject( “Photoshop.Application” )
appPhotoshop.BringToFront
appPhotoshop.DisplayDialogs = 3 ‘ psDisplayNoDialogs

Dim originalRulerUnits
originalRulerUnits = appRef.Preferences.RulerUnits
appRef.Preferences.RulerUnits = 1 ‘value of 1 = psPixels

‘*****************************************************************
‘** Process directory
Set objImgDir = objFSO.GetFolder(strImageDir)
For each objFile in objImgDir.Files
‘*****************************************************************
‘** If file is RAW image then Save as JPG
If IsRAW(objFile.Name) Then

strFileName = strImageDir & “\” & objFile.name
wscript.echo strFilename
Dim RAWOpenOptionsRef
Set RAWOpenOptionsRef = CreateObject(“Photoshop.CameraRAWOpenOptions”)
RAWOpenOptionsRef.Exposure = 0.5
RAWOpenOptionsRef.Contrast = 75
RAWOpenOptionsRef.Sharpness = 90

‘*****************************************************************
‘** Open the file in Photoshop
Set objImage = appPhotoshop.Open( strFileName, RAWOpenOptionsRef)

‘*****************************************************************
‘** Set jpg options
Set jpgSaveOptions = CreateObject( “Photoshop.JPEGSaveOptions” )
jpgSaveOptions.EmbedColorProfile = True
jpgSaveOptions.FormatOptions = 1 ‘ psStandardBaseline
jpgSaveOptions.Matte = 1 ‘ psNoMatte
jpgSaveOptions.Quality = 10
outFileName = strOutputDir & “\” & objFile.name
‘*****************************************************************
‘** Save the jpg image
objImage.SaveAs outFileName, jpgSaveOptions, True, extType
‘*****************************************************************
‘** Close image
objImage.close(2)
End If
Next
‘*****************************************************************
‘** Close Photoshop
appRef.Preferences.RulerUnits = originalRulerUnits
appPhotoshop.Quit

‘*****************************************************************
‘** End script
Wscript.Quit()

‘*****************************************************************
‘** Sub: DisplayHelp
‘** Version: 1.0
‘** Created: 24-03-2003 8:22
‘** Author: Adriaan Westra
‘** E-mail:
‘**
‘** Purpose / Comments:
‘** Display help for script
‘**
‘** Arguments :
‘**
‘** Wijzigingslog :
‘** 24-03-2003 8:22 : InitiĆ«le versie
‘**
‘*****************************************************************
Sub DisplayHelp()
strComment = string(2,”*”)
strCmntLine = String(79, “*”)
wscript.echo strCmntline
wscript.echo strComment
wscript.echo strComment & ” Online help for ” & _
Wscript.scriptname & ” version : ” & Version
wscript.echo strComment
wscript.echo strComment & ” Usage : cscript ” & _
Wscript.scriptname & ” directoryname”
wscript.echo strComment
wscript.echo strComment & ” Purpose : Convert raw nef ” & _
“files to jpg images in a given directory”
wscript.echo strComment
wscript.echo strComment & ” Author : ” & Author
wscript.echo strComment & ” E-mail : ” & Email
wscript.echo strComment
wscript.echo strCmntline
End Sub
‘*****************************************************************
‘** Function: IsRAW
‘** Version: 1.0
‘** Created: 12/29/2008 11:01PM
‘** Author: Adriaan Westra
‘** E-mail:
‘**
‘** Purpose / Comments:
‘** Determine if file is RAW image
‘**
‘** Arguments :
‘** strFilename : name of the file to check
‘**
‘** Wijzigingslog :
‘** 12/29/2008 11:02PM : InitiĆ«le versie
‘**
‘*****************************************************************
Function IsRAW(strFilename)
Set objRegExp = New RegExp
objRegExp.Pattern = “\w.nef”
objRegExp.IgnoreCase = True
IsRAW = objRegExp.Test(strFileName)
End Function

Geef een reactie