Skip to main content
Zee333
Inspiring
July 31, 2024
Answered

How to script a document mode change?

  • July 31, 2024
  • 1 reply
  • 799 views

For a project I'm working on I'm writing a Javascript code that does a bunch of things including resizing a document. I need to change it into index before I resize it so the edges don't get blurry and then change it back to RGB but so far nothing is working. Here is what I've been trying:

var srcDoc = app.activeDocument;
var pixelLoc = [1,1];
var colorSamplerRef = srcDoc.colorSamplers.add(pixelLoc);
app.foregroundColor = colorSamplerRef.color;
colorSamplerRef.remove()

srcDoc.changeMode(ChangeMode.INDEXEDCOLOR)
docRes = srcDoc.resolution
if (docRes/10 >= 10){
srcDoc.resizeImage(undefined, undefined, docRes/10, undefined, undefined);
}
else{}
srcDoc.changeMode(ChangeMode.RGB)

 The error right now is they want conversion options but I'm lost. Is there a way to say default? 

This topic has been closed for replies.
Correct answer Lumigraphics

I've seen this I was just unsure how to format the relevant information and pass it through the method


Specify properties with a name:value pair in brackets as below.

 

srcDoc.changeMode(ChangeMode.INDEXEDCOLOR, {colors:256, palette:Palette.EXACT, transparency:false})

1 reply

Legend
July 31, 2024

Put it into a try/catch block and post the exact error and line. Are you checking document.mode to see if what you are starting with?

Zee333
Zee333Author
Inspiring
July 31, 2024

The document is in RGB mode to start

Legend
July 31, 2024