• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Creating a custom gradient from Sample Image

Engaged ,
Apr 02, 2021 Apr 02, 2021

Copy link to clipboard

Copied

I have a simple noise-like gradient with lot of stops. I need a script that will sample each column of my document to get the color and add a stop to a gradient with that color. The end result would be a gradient fill pattern that matched the gradient in my image.

 

Ultimately, I want to use this new gradient to do a gradient map on a separate image.

 

This seems like it would be pretty easy to do, but I am having a hard time understanding JS in Photoshop...even with scriptListener installed. 

 

Any help would be greatly appreciated.

 

 

Views

188

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 02, 2021 Apr 02, 2021

Copy link to clipboard

Copied

I am trying to figure out the Photoshop DOM and it seems really strange to me. Here is some basic pseudocode that I thought I could just modify to work with PS, but it is not that easy I am finding.

let doc=document; //grab a reference to the current document
let cols=doc.getColumns(); //grab an array of references for 1px wide columns for the document;

let stops=[]; //these will be the gradient stops
let colCount=cols.length; //get the total count of columns
for (let colNum=0;colNum<colCount;colNum++) { //iterate through columns
    let theCol=cols[colNum]; //grab a reference to the column
    let colColor=getColorValue(theCol,[0,0]); //sample the top pixel in the column
stops.push({color:createColor(colColor), pos:createPos(colNum, colCount)});//push the color and the stop pct
}
let props={name:"testGradient"} //set any properties needed here
let grad=new PSgradient(props, stops); //creates the new gradient fill.
doc.addFill(grad); //adds the new gradient fill to the document

function getColorValue(colRef,pixelPos) {
//whatever it takes to sample the color of a column reference at a coordinate
}
function createColor(colorRef) {
    //whatever it takes to define a color in photoshop

}
function createPos (stopNum, stopCount) {
    return stopNum/stopCount; //may need to have integer stop percentages?
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

LATEST

The Photoshop DOM is indeed very confusing... 

 

ScriptListener is rapidly becoming the old way of doing things. You might give the Alchemist plugin a try... here's a video about it: https://www.davidebarranca.com/development/adobe-uxp-things-you-need-to-know-7-batchplay-part-2-alch...

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines