commit ef2c2743ec63d3009ddb442c0461b44ef3647c91 Author: maxxi Date: Fri Mar 27 00:30:51 2026 +0100 added tested script diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ba27a75 --- /dev/null +++ b/.gitignore @@ -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 diff --git a/SetEtikettSorte.ps1 b/SetEtikettSorte.ps1 new file mode 100644 index 0000000..459e241 --- /dev/null +++ b/SetEtikettSorte.ps1 @@ -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() \ No newline at end of file diff --git a/test.ps1 b/test.ps1 new file mode 100644 index 0000000..bcfbd0a --- /dev/null +++ b/test.ps1 @@ -0,0 +1,6 @@ +$Datum = "26.03.2026" + +$parsedDate = [datetime]::ParseExact($Datum, "dd.MM.yyyy", $null) +$OutDate = $parsedDate.ToString("yyyy-MM-dd") + +Write-Host $OutDate \ No newline at end of file