'Any way to use external list of color hex codes to change layer fill in Photoshop?
I have a list of 100 different color hex codes. I want to create 100 different PNG files, that each use a different color from this list.
Apparently I cannot use variables in Photoshop, so I am looking for another way, since I am not a scripting guru.
If scripting is the only way, is there a simple language to leverage like VB, Powershell, etc., versus trying to learn Javascript, et al?
Thank you
Solution 1:[1]
Maybe learning JavaScript would ultimately allow a simplified approach, but this is what I did.
First I created a CSV file of the color hex codes I wanted:
filename red green blue BackGround1 255 255 255 Then I created a PowerShell script to generate a PNG file for each color:
# Specify the path of the Excel or csv data file $FilePath = "C:\...\BackgroundColors.csv" # Specify the starting and ending data rows $RowStart = 2 $RowEnd = 101 # Specify the Sheet name $SheetName = "BackgroundColors" # Create an Object Excel.Application using Com interface $ObjExcel = New-Object -ComObject Excel.Application # Disable the 'visible' property so the document won't open in excel $ObjExcel.Visible = $false # Open the Excel file and save it in $WorkBook $WorkBook = $ObjExcel.Workbooks.Open($FilePath) # Load the WorkSheet $WorkSheet = $WorkBook.sheets.item($SheetName) # Set Image file SaveTo location $SaveTo ="C:\...\Backgrounds" # Instatiate Image Com Interface Add-Type -AssemblyName System.Drawing #Loop for ($counter = $RowStart; $counter -le $RowEnd; $counter++ ) { # Set Image variable $SaveAs = $WorkSheet.Range("A$counter").text $Red = $WorkSheet.Range("B$counter").text $Green = $WorkSheet.Range("C$counter").text $Blue = $WorkSheet.Range("D$counter").text $FileName = "$SaveTo\$SaveAs.png" #Create bitmap $bmp = new-object System.Drawing.Bitmap 750,750 #Create brush with color $brush = [System.Drawing.SolidBrush]::New([System.Drawing.Color]::FromArgb(255, $Red, $Green, $Blue)) $graphics = [System.Drawing.Graphics]::FromImage($bmp) $graphics.FillRectangle($brush,0,0,$bmp.Width,$bmp.Height) $graphics.Dispose() $bmp.Save($FileName) } $workbook.Close($false) $objExcel.Quit() # release Com objects [System.Runtime.Interopservices.Marshal]::ReleaseComObject($Worksheet) | Out-Null [System.Runtime.Interopservices.Marshal]::ReleaseComObject($Workbook) | Out-Null [System.Runtime.Interopservices.Marshal]::ReleaseComObject($objExcel) | Out-Null # Force garbage collection [System.GC]::Collect()
I understand there are probably better ways, instead of using the Excel file approach, but I wanted to learn how to leverage Excel with PowerShell.
Then in PhotoShop I created a template, with a layer that I could replace with each of the files I created, along with other files to compose the complete image I wanted:
File > New
Image > Variables > Define > Pixel Replacement
I created another CSV file with the paths to the image files I created:
newfilename background path image path NewImageName C:\...\BackGround1.png C:\...\Image1.png Then in Photoshop I imported the CSV file as a data set:
Image > Variables > Data Sets > Import
Then exported the data set as files, which created PSD files:
File > Export > Data Sets as Files
Then I created a Photoshop Action to save a PSD file as a PNG file:
Window > Actions > Create New Action > Record
Then I ran the Action as a Batch against all the PSD files:
File > Automate > Batch > MyActions
There are certainly more details involved than presented here, but this approach enabled me to automate the creation of the backgrounds, then combine them with other images, to ultimately create a variety of new images quickly. It wasn't quick getting the whole process worked out, but now it is quickly repeatable, and over time can be improved with additional knowledge and capabilities.
Solution 2:[2]
This is the general premise, for each image change hexcol:
var hexcol = "ff00ff"; // change this to alter the colour
var col = new SolidColor;
col.rgb.hexValue = hexcol;
app.activeDocument.selection.fill(col, ColorBlendMode.NORMAL, 100, false);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | RobC |
Solution 2 | RobC |