FORUM NIKONCLUB

Condividi le tue conoscenze, aiuta gli altri e diventa un esperto.

Chiudi
TITOLO*
DOMANDA*
AREA TEMATICA INTERESSATA*
Script Photoshop
..in caso vi servisse
Rispondi Nuova Discussione
LightPainting
Messaggio: #1
Basandomi su uno degli standard ho creato questo semplice script photoshop in VB per una procedura qua al lavoro. Data una cartella sorgente, per ogni sottocartella al primo livello (quindi non le sottocartelle della sottocartella), vengono ridimensionate tutte le immagini jpg e salvate in una sottocartella "ridotto" creata automaticamente. Lo script controlla la dimensione dell'immagine e imposta il lato piu lungo alla dimensione definita nella variabile (per risolvere il problema dell'orientamento).
Spero vi possa essere utile
Fabry

(utilizzare il file allegato da rinominare in vbs)

Option Explicit

Option Explicit
' Impostare qui la dimensione del lato piu lungo
Const C_Resize = 500
' Impostare qui la qualita del jpg
Const C_JpegQuality = 6

Dim appRef
Dim docRef
Dim docInfoRef
Dim fsoRef
Dim folderRef
Dim rootFolderRef
Dim convertedFolderRef
Dim fileCollection
Dim fileRef
Dim extType
Dim newFileName1
Dim newFolderName
Dim saveOptionsRef
Dim strtRulerUnits
Dim jpgSaveOptions
Dim i
Dim folderPath
Dim xSize
Dim ySize

Set appRef = CreateObject( "Photoshop.Application" )

'appRef.BringToFront

'appRef.DisplayDialogs = 3 ' psDisplayNoDialogs

Set fsoRef = CreateObject( "Scripting.FileSystemObject" )
' Impostare qui il percorso della cartella sorgente
folderPath = "c:\sorgente"

If (not fsoRef.FolderExists(folderPath)) Then
msgbox folderPath & " non esistente"
wscript.quit
end if

set rootFolderRef = fsoRef.GetFolder( folderPath )

for each folderRef in rootFolderRef.SubFolders

' Impostare qui il nome della cartella di destinazione ridotte
newFolderName = folderRef & "\Ridotto"
saveOptionsRef = 2 ' psDoNotSaveChanges

If fsoRef.FolderExists( newFolderName ) Then
Set convertedFolderRef = fsoRef.GetFolder( newFolderName )
Else
Set convertedFolderRef = fsoRef.CreateFolder( newFolderName )
End If

Set fileCollection = folderRef.Files
extType = 2 ' psLowercase

strtRulerUnits = appRef.Preferences.RulerUnits
'appRef.Preferences.RulerUnits = 2 ' psInches
appRef.Preferences.RulerUnits = 1 ' psPixels

appref.Visible = false

For Each fileRef In fileCollection
if ucase(right(fileRef.Name,3)) = "JPG" then


Set docRef = appRef.Open( fileRef.Path )
' Impostazione dati exif
Set docInfoRef = docRef.Info
docInfoRef.Copyrighted = 1 ' psCopyrightedWork
docInfoRef.CopyrightNotice = "nome copyright"


' Ridimensionamento immagine
xSize= docRef.Width
ySize= docRef.Height


if (xSize > C_Resize or ySize > C_Resize) then

if xSize > ySize then
xSize = C_Resize
ySize = ySize * (xSize / docRef.Width)
else
ySize = C_Resize
xSize = xSize * (ySize / docRef.Height)
end if

docRef.ResizeImage xSize, ySize
end if

' impostazione jpg
Set jpgSaveOptions = CreateObject( "Photoshop.JPEGSaveOptions" )
jpgSaveOptions.EmbedColorProfile = True
jpgSaveOptions.FormatOptions = 1 ' psStandardBaseline
jpgSaveOptions.Matte = 1 ' psNoMatte
jpgSaveOptions.Quality = C_JpegQuality

' Impostazione nome file prodotto
newFileName1 = convertedFolderRef.Path & "\" & fileRef.Name

' Salvataggio e chiusura del file
docRef.SaveAs newFileName1, jpgSaveOptions, True, extType

docRef.Close saveOptionsRef
end if
Next
next

appref.Visible = true
File allegati
File Allegato  script.txt ( 2.45k ) Numero di download: 49
 
lucaoms
Messaggio: #2
grazie per il tempo "perso" anche se perso non è e per averlo voluto condividere!!!
Bello e lungo lavoro!!
luca
 
Discussioni simili Iniziata da Forum Risposte Ultimo messaggio