Skip to main content
Participant
September 11, 2018
Answered

RGB and Hexadecimal Codes in Text Layer

  • September 11, 2018
  • 1 reply
  • 659 views

Hi,

I try to read Colors with Color Sampler at different positions an paste the colorcode in a text Layer.

RGB,LAB,HSB is no Problem

parseInt( foregroundColor.rgb.red)

parseInt( foregroundColor.hsb.hue)

parseInt( foregroundColor.lab.l)

but how i can get the Hexadecimal/Web Code?

#target photoshop

 

app.activeDocument.colorSamplers.removeAll();

var docRef = app.activeDocument
var pixelLoc = [UnitValue("1000 pixels") , UnitValue("240 pixels")];
var colorSamplerRef = docRef.colorSamplers.add(pixelLoc);
app.foregroundColor = colorSamplerRef.color
var doc = activeDocument; 
var txtLayer = doc.layers.getByName('A1'); 
doc.activeLayer = txtLayer 
txtLayer.textItem.contents = 'R: '+  parseInt( foregroundColor.rgb.red) + '\rG: ' + parseInt(foregroundColor.rgb.green) +  '\rB: ' + parseInt(foregroundColor.rgb.blue) +  '\rH: ' + parseInt(foregroundColor.rgb.hexvalue)

var docRef = app.activeDocument
var pixelLoc = [UnitValue("1000 pixels") , UnitValue("240 pixels")];
var colorSamplerRef = docRef.colorSamplers.add(pixelLoc);
app.foregroundColor = colorSamplerRef.color
var doc = activeDocument; 
var txtLayer = doc.layers.getByName('A2'); 
doc.activeLayer = txtLayer 
txtLayer.textItem.contents = 'R: '+  parseInt( foregroundColor.rgb.red) + '\rG: ' + parseInt(foregroundColor.rgb.green) +  '\rB: ' + parseInt(foregroundColor.rgb.blue)

This topic has been closed for replies.
Correct answer r-bin

replace

parseInt(foregroundColor.rgb.hexvalue)

to

foregroundColor.rgb.hexValue

1 reply

r-binCorrect answer
Legend
September 11, 2018

replace

parseInt(foregroundColor.rgb.hexvalue)

to

foregroundColor.rgb.hexValue