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

How to convert image to CMYK (from any format)?

Community Beginner ,
Jan 21, 2016 Jan 21, 2016

Copy link to clipboard

Copied

This seems like it should be pretty simple.

I tried to reverse engineer a function from the "Warn if RGB.jsx" found: applications/Adobe Photoshop CC 2015/ Presets/Scripts/Warn if RGB.jsx

in this file the image that is open in Photoshop is taken and converted to RGB.

Well that's exactly what I want to do, except the reverse.

How do I write code that would take my "current image" and change it to CMYK just as if I were to go into photoshop (GUI) Edit> Convert to Profile... > and select the CMYK bullet option under "Destination Space"

I need this in a function for other script I have.

I will past what I have (with my poor attempt at reverse engineering the "Warn if RGB.jsx" function in place.

Thank you. I could really use the help and I think this should be pretty straight forward.

try {

  var data = GetDataFromDocument( activeDocument );

  if ('eps' == data.extension.toLowerCase()) {

  //convert to cmyk

  Switch();

  }

  else{

  //run code to square up images

  toSquare();

  }

}

catch( e ) {

  alert(e);

}

//FUNCTIONS

///////////////////////////////////////////////

///////////////////////////////////////////////

function toSquare(){

  var savedRuler= app.preferences.rulerUnits;

  app.preferences.rulerUnits = Units.PIXELS;

  var w = app.activeDocument.width;

  var h = app.activeDocument.height;

  if(w>h) app.activeDocument.resizeCanvas (w, w, AnchorPosition.MIDDLECENTER);

  if(w<h) app.activeDocument.resizeCanvas (h, h, AnchorPosition.MIDDLECENTER);

  //if w==h already square

  app.preferences.rulerUnits = savedRuler;

}

///////////////////////////////////////////////

function GetDataFromDocument( inDocument ) {

  var data = new Object();

  var fullPathStr = inDocument.fullName.toString();

  var lastDot = fullPathStr.lastIndexOf( "." );

  var fileNameNoPath = fullPathStr.substr( 0, lastDot );

  data.extension = fullPathStr.substr( lastDot + 1, fullPathStr.length );

  var lastSlash = fullPathStr.lastIndexOf( "/" );

  data.fileName = fileNameNoPath.substr( lastSlash + 1, fileNameNoPath.length );

  data.folder = fileNameNoPath.substr( 0, lastSlash );

  data.fileType = inDocument.fullName.type;

  return data;

}

///////////////////////////////////////////////

function Switch() {

  var eventModeChange = stringIDToTypeID( "8cba8cd6-cb66-11d1-bc43-0060b0a13dc4" );

  var descSource = new ActionDescriptor();

  var keySourceMode = charIDToTypeID( "SrcM" );

  var list = new ActionList();

  var keyCondition = charIDToTypeID( "Cndn" );

  var keyBitmap = charIDToTypeID( "UBtm" );

  var keyGrayscale = charIDToTypeID( "UGry" );

  var keyDuotone = charIDToTypeID( "UDtn" );

  var keyIndex = charIDToTypeID( "UInd" );

  var keyRGB = charIDToTypeID( "URGB" );

  var keyCMYK = charIDToTypeID( "UCMY" );

  var keyLab = charIDToTypeID( "ULab" );

  var keyMultichannel = charIDToTypeID( "UMlt" );

  list.putEnumerated( keyCondition, keyBitmap );

  list.putEnumerated( keyCondition, keyGrayscale );

  list.putEnumerated( keyCondition, keyDuotone );

  list.putEnumerated( keyCondition, keyIndex );

  list.putEnumerated( keyCondition, keyRGB );

  list.putEnumerated( keyCondition, keyCMYK );

  list.putEnumerated( keyCondition, keyLab );

  list.putEnumerated( keyCondition, keyMultichannel );

  descSource.putList( keySourceMode, list );

  var keyDestination = charIDToTypeID( "DstM" );

  var descDest = new ActionDescriptor();

  var keyCMYK = charIDToTypeID( "UCMY" );

  descSource.putObject( keyDestination, keyRGB, descDest );

  executeAction( eventModeChange, descSource, DialogModes.NO );

}

//////////////////////////////////////////////

//////////////////////////////////////////////

TOPICS
Actions and scripting

Views

1.5K

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

correct answers 1 Correct answer

Contributor , Jan 22, 2016 Jan 22, 2016

Seems like the forum engine swallowing random whitespaces when we switch to advanced editor mode:

The exact line is this:

var idT = charIDToTypeID( "T   " );

There are 3 spaces after the T.

Votes

Translate

Translate
Adobe
Contributor ,
Jan 21, 2016 Jan 21, 2016

Copy link to clipboard

Copied

function converToCMYK( rasterize )

{

    var idCnvM = charIDToTypeID( "CnvM" );

    var desc39 = new ActionDescriptor();

    var idT = charIDToTypeID( "T  " );

    var idCMYM = charIDToTypeID( "CMYM" );

    desc39.putClass( idT, idCMYM );

    var idMrge = charIDToTypeID( "Mrge" );

    desc39.putBoolean( idMrge, false );

    var idRstr = charIDToTypeID( "Rstr" );

    desc39.putBoolean( idRstr, rasterize );

    executeAction( idCnvM, desc39, DialogModes.NO );

}

converToCMYK ( rasterize = true ) ;

This code is copied from ScriptingListenerJS.log which is the output of the ScriptListener.8li plugin.

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
Community Beginner ,
Jan 22, 2016 Jan 22, 2016

Copy link to clipboard

Copied

When I try this code, the resulting error is:

Screen Shot 2016-01-22 at 7.49.52 AM.png

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
Contributor ,
Jan 22, 2016 Jan 22, 2016

Copy link to clipboard

Copied

Seems like the forum engine swallowing random whitespaces when we switch to advanced editor mode:

The exact line is this:

var idT = charIDToTypeID( "T   " );

There are 3 spaces after the T.

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
Community Beginner ,
Jan 22, 2016 Jan 22, 2016

Copy link to clipboard

Copied

LATEST

oliverIntergrafika wrote:

  1. function converToCMYK( rasterize ) 
  2.     var idCnvM = charIDToTypeID( "CnvM" ); 
  3.     var desc39 = new ActionDescriptor(); 
  4.     var idT = charIDToTypeID( "T  " ); 
  5.     var idCMYM = charIDToTypeID( "CMYM" ); 
  6.     desc39.putClass( idT, idCMYM ); 
  7.     var idMrge = charIDToTypeID( "Mrge" ); 
  8.     desc39.putBoolean( idMrge, false ); 
  9.     var idRstr = charIDToTypeID( "Rstr" ); 
  10.     desc39.putBoolean( idRstr, rasterize ); 
  11.     executeAction( idCnvM, desc39, DialogModes.NO ); 
  12.  
  13. converToCMYK ( rasterize = true ) ; 

This code is copied from ScriptingListenerJS.log which is the output of the ScriptListener.8li plugin.

So this is the correct answer when taken into account the 3 spaces after  the T in : var idT = charIDToTypeID( "T  " );

Thank you so much!!

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