added tested script
This commit is contained in:
20
.gitignore
vendored
Normal file
20
.gitignore
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# Ignore generated images
|
||||||
|
|
||||||
|
*.jpg
|
||||||
|
*.jpeg
|
||||||
|
*.png
|
||||||
|
|
||||||
|
# Ignore Photoshop files
|
||||||
|
|
||||||
|
*.psd
|
||||||
|
*.psb
|
||||||
|
|
||||||
|
# Optional: ignore temp / export files
|
||||||
|
|
||||||
|
*.tmp
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# Optional: ignore OS files
|
||||||
|
|
||||||
|
Thumbs.db
|
||||||
|
.DS_Store
|
||||||
150
SetEtikettSorte.ps1
Normal file
150
SetEtikettSorte.ps1
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
param(
|
||||||
|
[string]$InputFile = "C:\Temp\git\PS-SetEtikettSorte\500GrammEtikett.psd",
|
||||||
|
[Parameter(Mandatory)]
|
||||||
|
[string]$Sorte,
|
||||||
|
[string]$Sorte2,
|
||||||
|
[Parameter(Mandatory)]
|
||||||
|
[string]$Datum
|
||||||
|
)
|
||||||
|
|
||||||
|
# --- Encoding ---
|
||||||
|
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
||||||
|
|
||||||
|
# --- Photoshop starten ---
|
||||||
|
$ps = New-Object -ComObject Photoshop.Application
|
||||||
|
$ps.Visible = $false
|
||||||
|
$ps.Preferences.RulerUnits = 1 # Pixel
|
||||||
|
|
||||||
|
# --- Helper: Dateiname säubern ---
|
||||||
|
function Sanitize-FileName($name) {
|
||||||
|
if (-not $name) { return "" }
|
||||||
|
$name = $name -replace '[\\/:*?"<>|]', '_'
|
||||||
|
$name = $name -replace '\s+', '-'
|
||||||
|
$name = $name -replace '&', '-'
|
||||||
|
return $name
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- Datum umwandeln ---
|
||||||
|
$parsedDate = [datetime]::ParseExact($Datum, "dd.MM.yyyy", $null)
|
||||||
|
$OutDate = $parsedDate.ToString("yyyy-MM-dd")
|
||||||
|
|
||||||
|
$SorteSafe = Sanitize-FileName $Sorte
|
||||||
|
$Sorte2Safe = Sanitize-FileName $Sorte2
|
||||||
|
|
||||||
|
# --- PSD öffnen ---
|
||||||
|
$doc = $ps.Open($InputFile)
|
||||||
|
|
||||||
|
# --- Text setzen ---
|
||||||
|
try {
|
||||||
|
$doc.ArtLayers.GetByName("Sorte").TextItem.Contents = "Deutscher $Sorte"
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$layer2 = $doc.ArtLayers.GetByName("Sorte2")
|
||||||
|
if (-not [string]::IsNullOrWhiteSpace($Sorte2)) {
|
||||||
|
$layer2.TextItem.Contents = "mit $Sorte2"
|
||||||
|
} else {
|
||||||
|
$layer2.TextItem.Contents = ""
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$doc.ArtLayers.GetByName("Datum").TextItem.Contents = $Datum
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
# --- Output Name ---
|
||||||
|
if ($Sorte2Safe) {
|
||||||
|
$OutputFile = "C:\Temp\git\PS-SetEtikettSorte\${OutDate}_${SorteSafe}_mit_${Sorte2Safe}.jpg"
|
||||||
|
} else {
|
||||||
|
$OutputFile = "C:\Temp\git\PS-SetEtikettSorte\${OutDate}_${SorteSafe}.jpg"
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- Export Einzeletikett ---
|
||||||
|
$doc.Export($OutputFile, 2)
|
||||||
|
$doc.Close(2)
|
||||||
|
|
||||||
|
# =====================================================
|
||||||
|
# ================== A4 GENERIERUNG ===================
|
||||||
|
# =====================================================
|
||||||
|
|
||||||
|
$A4Template = "C:\Temp\git\PS-SetEtikettSorte\Druckvorlage_A4.psd"
|
||||||
|
$docA4 = $ps.Open($A4Template)
|
||||||
|
|
||||||
|
# --- Helper: Bild einfügen ---
|
||||||
|
function Place-Image {
|
||||||
|
param($file, $targetDoc)
|
||||||
|
|
||||||
|
$imgDoc = $ps.Open($file)
|
||||||
|
$imgDoc.Selection.SelectAll()
|
||||||
|
$imgDoc.Selection.Copy()
|
||||||
|
$imgDoc.Close(2)
|
||||||
|
|
||||||
|
$ps.ActiveDocument = $targetDoc
|
||||||
|
$targetDoc.Paste()
|
||||||
|
|
||||||
|
return $targetDoc.ActiveLayer
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- Größe ermitteln ---
|
||||||
|
$ps.ActiveDocument = $docA4
|
||||||
|
$layer = Place-Image $OutputFile $docA4
|
||||||
|
|
||||||
|
$bounds = $layer.Bounds
|
||||||
|
$width = [int]$bounds[2] - [int]$bounds[0]
|
||||||
|
$height = [int]$bounds[3] - [int]$bounds[1]
|
||||||
|
|
||||||
|
# löschen (sauber)
|
||||||
|
$ps.ActiveDocument = $docA4
|
||||||
|
$layer = $docA4.ActiveLayer
|
||||||
|
|
||||||
|
if ($layer) {
|
||||||
|
$layer.Delete()
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- Grid Parameter ---
|
||||||
|
$cols = 1
|
||||||
|
$rows = 6
|
||||||
|
$gapX = 60
|
||||||
|
$gapY = 100
|
||||||
|
|
||||||
|
$offsetX = 100
|
||||||
|
$offsetY = 100
|
||||||
|
|
||||||
|
# --- Platzierung ---
|
||||||
|
for ($r = 0; $r -lt $rows; $r++) {
|
||||||
|
for ($c = 0; $c -lt $cols; $c++) {
|
||||||
|
|
||||||
|
$ps.ActiveDocument = $docA4
|
||||||
|
|
||||||
|
#Place-Image $OutputFile $docA4
|
||||||
|
[void](Place-Image $OutputFile $docA4)
|
||||||
|
|
||||||
|
$layer = $docA4.ActiveLayer
|
||||||
|
|
||||||
|
$bounds = $layer.Bounds
|
||||||
|
$currentX = [int]$bounds[0]
|
||||||
|
$currentY = [int]$bounds[1]
|
||||||
|
|
||||||
|
$targetX = $offsetX + ($c * ($width + $gapX))
|
||||||
|
$targetY = $offsetY + ($r * ($height + $gapY))
|
||||||
|
|
||||||
|
$moveX = $targetX - $currentX
|
||||||
|
$moveY = $targetY - $currentY
|
||||||
|
|
||||||
|
$docA4.ActiveLayer = $layer
|
||||||
|
$layer.Translate($moveX, $moveY)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- Final Output ---
|
||||||
|
if ($Sorte2Safe) {
|
||||||
|
$FinalOutput = "C:\Temp\git\PS-SetEtikettSorte\${OutDate}_A4_${SorteSafe}_mit_${Sorte2Safe}.jpg"
|
||||||
|
} else {
|
||||||
|
$FinalOutput = "C:\Temp\git\PS-SetEtikettSorte\${OutDate}_A4_${SorteSafe}.jpg"
|
||||||
|
}
|
||||||
|
|
||||||
|
$ps.ActiveDocument = $docA4
|
||||||
|
$docA4.Export($FinalOutput, 2)
|
||||||
|
$docA4.Close(2)
|
||||||
|
|
||||||
|
$ps.Quit()
|
||||||
Reference in New Issue
Block a user