Create plain color files

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: xbytor, DavideBarranca, Paul MR

Sara
Posts: 1
Joined: Fri Feb 16, 2018 3:45 am

Create plain color files

Postby Sara » Fri Feb 16, 2018 4:26 am

Hi,

Hoping someone can help with this, I found this post which was almost 10 years old! It seems that it will do what I need, but it errors on line 27
With "Error 1220 Illegal Argument color.rbg["hexValue"]=part[1];

Thank you :-)
Try this:

CSV:Code: Select allorange,fe7011
apple,c80303
banana,ffd800
pear,00ff00

JSX:Code: Select allfunction SaveJPEG(saveFile, jpegQuality){
   jpgSaveOptions = new JPEGSaveOptions()
   jpgSaveOptions.embedColorProfile = true
   jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE
   jpgSaveOptions.matte = MatteType.NONE
   jpgSaveOptions.quality = jpegQuality //1-12
   activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE)
}

// read in result file
var crop = new File("/c/sandbox/fruit.csv");

// open file
crop.open('r');

while (!crop.eof)
{
   // read line of csv
   var line = crop.readln();
   var part = line.split(',');

   // create doc
   var doc = app.documents.add(100, 100, 72, part[0], NewDocumentMode.RGB);

   // define your fill color
   var color = new SolidColor();
   color.rgb["hexValue"] = part[1];
   
   // fill layer
   doc.selection.selectAll();
   doc.selection.fill(color);
   
   // save file
   var image = new File("/c/sandbox/"+ part[0] +".jpg");
   SaveJPEG(image,12);

   // close document
   doc.close(SaveOptions.DONOTSAVECHANGES);

}

// close file
crop.close();


Patrick

ddcg
Posts: 1
Joined: Tue Aug 29, 2017 3:58 pm

Re: Create plain color files

Postby ddcg » Tue Dec 18, 2018 9:09 pm

A little late to the party here...stumbled across your question and thought I'd share something I created recently that will do a similar thing.

This script will create a solid color layer with a random color from a series of pre-selected hex codes...so the idea is you populate the array with hex vals for colors you want it to choose from and then it'll randomly pick one of those colors for each iteration of the loop.

The loop is determined by 'n'. Change the value of n to however many files you want it to create and that's it; hit play and walk away :)

Code: Select all

var currentRulers = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.INCHES;

// SAVE PATH
var rootFolder = new Folder(Folder.desktop + "/Solid Colors");

// CREATE SAVE PATH IF IT DOESN'T EXIST
if (!rootFolder.exists) {
rootFolder.create()
}

// RANDOM NUMBER GENERATOR
function rando(min, max) {
return Math.floor(Math.random() * (max - min + 1) ) + min;
}

// SAVE AS A TIFF
function saveTiff(savePath, newName) {

var activeDoc = app.activeDocument;
var w = activeDoc.width.value
var h = activeDoc.height.value
var revWidth = (Math.floor(w)).toString();
var revHeight = (Math.floor(h)).toString();

var saveOpts = new TiffSaveOptions();
saveOpts.alphaChannels = false;
saveOpts.interleaveChannels = true;
saveOpts.imageCompression = TIFFEncoding.TIFFLZW;

activeDoc.saveAs(new File(savePath + "/" + newName + " " + revWidth + "x" + revHeight + ".tif"), saveOpts);
activeDoc.close();
}

var n = 10; // CHANGE N TO THE NUMBER OF FILES YOU WANT THE SCRIPT TO CREATE

var masterWidth = 5; // SET YOUR DOCUMENT WIDTH
var masterHeight = 5; // SET YOUR DOCUMENT HEIGHT
var masterRes = 300; // SET YOUR DOCUMENT RESOLUTION

// ADD MORE HEX CODES TO INCLUDE DIFFERENT COLORS
var hexVals = [
"dcb149", //mustard yellow
"e8d279", //canary yellow
"bd6124", //light orange
"c53c12", //orange red
"991a1a", //dk red
"991a38", //fuscia
"f1725e", //salmon
"441848", //plum
"3c1f35", //blackberry
"2d1c43", //grape
"5088ac", //sky blue
"20beda", //baby blue
"426277", //ocean blue
"1b2a4a", //navy blue
"274685", //royal blue
"468684", //sea foam blue / green
"3a6c4a", //kelly green
"304d2d", //forest green
"2e3a1c", //army green
"4d541d", //moss green
"6f6a6c", //warm med gray
"252424", //warm dk gray
"b9b6b7" //light gray

]

for (i = 0; i < n; i++) {
var h = rando(0, (hexVals.length - 1));
app.foregroundColor.rgb.hexValue = hexVals[h];

//alert(app.foregroundColor.rgb.hexValue)
app.documents.add(masterWidth, masterHeight, masterRes, "Untitled " + i, NewDocumentMode.RGB, DocumentFill.WHITE);
var doc = app.activeDocument;
var colorLayer = doc.artLayers.add();
app.activeLayer = colorLayer;
doc.selection.selectAll();
doc.selection.fill(app.foregroundColor);
colorLayer.move(doc.backgroundLayer, ElementPlacement.PLACEBEFORE);
saveTiff(rootFolder, "Solid Color " + i)
}

app.preferences.rulerUnits = currentRulers;


Return to “Help Me”

Who is online

Users browsing this forum: No registered users and 3 guests