現在數碼相片多了,處理起來也很費勁的。
通過實踐,發現 Photoshop 的腳本功能非常強大。就想利用其功能,實現自動化處理。Photoshop 的腳本開發,可以參考 C:\Program Files\Adobe\Adobe Photoshop CS2\Scripting Guide 下面相應的 .pdf,有 Javascript、vbscript 等的語言可選。
下面是一個范例:
Option Explicit
''''Batch converter for Photoshop CS2(Not tested for CS1)
''author: cangwu.lee # gmail.com
''saving parameter
Const psSaveChanges = 1
Const psDoNotSaveChanges = 2
Const psPromptToSaveChanges = 3
''Jpeg Option
Const psStandarDBaseline = 1
Const psOptimizeDBaseline = 2
Const psProgressive = 3
''saveAs PsExtensionType
Const PsExtensionType_psLowercase = 2
Const PsExtensionType_psUppercase = 3
''PsDialogModes
Const psDisplayAllDialogs = 1
Const psDisplayErrorDialogs = 2
Const psDisplayNoDialogs = 3
const imageFilter = ";PSD;BMP;JPG;JPEG;GIF;PNG;" ''image file type to process
dim directory, JSxFile, jpeg_quality
directory = "c: emp" ''change to point to your photos folder
jsxFile = "C:\Program Files\Adobe\Adobe Photoshop CS2\Presets\Scripts\exif_info.JSx"
jpeg_quality = 8 ''between 1~12
''將這3個變量改成你的實際需要。
call convert2jpegByFolder()
''
Function convert2jpegByFolder()
Dim i
Dim fs, objFiles, objFile, ext, idone, IError
Set fs = CreateObject("Scripting.FileSystemObject")
If Not fs.fileExists(JSxFile) Then
MsgBox "The .JSx file NOT exists."
Exit Function
End If
If Not fs.folderexists(directory) Then
MsgBox "Photo directory NOT exists."
Exit Function
End If
Dim appRef '' As Photoshop.Application
Dim docRef '' As Photoshop.Document
Set appRef = GetObject("", "Photoshop.Application")
If Err.Number <> 0 Then
Set appRef = CreateObject("Photoshop.Application")
End If
If appRef Is Nothing Then
MsgBox "Photoshop Appliaction object exception."
Exit Function
End If
Dim jpgOpt''Photoshop.JPEGSaveOptions
Set jpgOpt = CreateObject("Photoshop.JPEGSaveOptions")
With jpgOpt
.FormatOptions = psStandarDBaseline
.Quality = jpeg_quality ''0~12
End With
appRef.Preferences.TypeUnits = 1 ''for PsTypeUnits --> 1 (psPixels)
appRef.DisplayDialogs = psDisplayNoDialogs
Set objFiles = fs.GetFolder(directory).Files
If Err.Number <> 0 Then MsgBox Err.Description: Exit Function
On Error GoTo 0
MsgBox "All file in the directory conuters:" & objFiles.Count & chr(13) & chr(10) & "Click ''OK'' to continue."
idone = 0
For Each objFile In objFiles
ext =";" & UCase(fs.GetExtensionName(objFile.Path)) & ";"
If instr(1, imageFilter, ext, 1)>0 Then
''set docRef = appRef.Documents.Add(1024, 768)
Set docRef = appRef.Open(objFile.Path)
If docRef Is Nothing Then
MsgBox "Create/open image document failed."
Else
''setting current picture document
Set appRef.ActiveDocument = docRef
''begin to process
On Error Resume Next
Call appRef.DoJavaScriptFile(JSxFile)
If Err.Number = 0 Then
For i = 0 To 30000
''waiting for some times
Next
Call docRef.SaveAs(objFile.Path & ".jpg", jpgOpt, True, PsExtensionType_psLowercase)
Else
&nbs ierror = IError + 1
End If
On Error GoTo 0
''close document
Call docRef.Close(psDoNotSaveChanges)
idone = idone + 1 ''''counter
Set docRef = Nothing '' free document object
End If
End If
Next
MsgBox "Image files:" & idone & chr(13) & chr(10) & "File error:" & IError
Set appRef = Nothing
End Function
將文字保存成一個 .vbs 文件,雙擊 執行,立等可取!
本腳本僅僅作為示范,未能保證在其它電腦也能執行順利。但,不對原文件進行修改(因為修改之後不保存、或者另存為了),不會造成文件丟失。