Skip to main content
Inspiring
January 10, 2025
Answered

Converting RGB images in InDesign using Photoshop's 'Convert to Profile'

  • January 10, 2025
  • 4 replies
  • 2372 views

Hi,

 

I want my RGB images in InDesign to convert to CMYK using the Photoshop's 'Convert to Profile' method. I found this script on the net:

http://kasyan.ho.ua/indesign/swatch_color/convert_rgb_grayscale_images_to_cmyk.html

 

However, this script is using the Change Mode method, whereas I want the 'Convert to Profile' method to convert my images to CMYK along with an option to select the desired Colour Profile from the Dropdown list. Like we do in Photoshop > Convert to Profile > select destination profile.

 

Any suggestions.

Correct answer Eugene Tyson

Hi Eugene,

 

You have given me my code in return, there's no difference, the script is pulling the profile's list manually instead of auto-fetching.  I think this is not a doable task, so let's close this chapter here.

 

Anyway, thanks everyone for your time and suggestions!


Oops must have copied the wrong code

 

Try this for auto fetching

 

function getAvailableCMYKProfiles() {
    var profiles = app.colorSettings.workingSpaceCMYKList;
    return profiles;
}

function getCMYKProfile() {
    var profiles = getAvailableCMYKProfiles();
    if (profiles.length === 0) {
        alert("No CMYK profiles available.");
        return null;
    }
    return showDropdown(profiles);
}

function showDropdown(profiles) {
    var dialog = new Window("dialog", "Select CMYK Profile");
    dialog.orientation = "column";
    var dropdown = dialog.add("dropdownlist", undefined, profiles);
    dropdown.selection = 0;
    dialog.add("button", undefined, "OK", { name: "ok" });

    if (dialog.show() == 1) {
        return dropdown.selection.text;
    } else {
        return null;
    }
}

4 replies

Inspiring
January 11, 2025

Opinios, opinions, and opinions, that's all I get here.

 

As I said, I know all these things.

I can simply open the images in Photoshop and do the conversion.

I am also aware of the Batch thing.

I know the importance of RGB images and converting them while exporting a PDF.

I know the difference between Change-Mode and Convert-to-Profile methods.

I know the usage and differences between JPG, PNG Tiff etc images.

I know this, I know that.............................................................................

 

What I was looking is a JavaSript which when executed from InDesign tracks all the RGB images and convert them to CMYK. The script from Kasyan's site is very useful and I'm able to modify it to use the 'Convert to Profile' method, and also able to create a manual color profile list. The modified version is working fine. Here are the excerpts:

"    if (psDoc) {" +
"        psDoc.convertProfile('" + profile + "', Intent.RELATIVECOLORIMETRIC, true);" +
"        psDoc.save();" +
"        psDoc.close(SaveOptions.SAVECHANGES);" +

 

function getCMYKProfile() {
    var profiles = [
    "Coated FOGRA39 (ISO 12647-2:2004)",
    "Coated FOGRA27 (ISO 12647-2:2004)",
    "Coated GRACoL 2006 (ISO 12647-2:2004)",
    "ISO Web Coated",

I was wondering if the script could auto fetch the profile list as Photoshop do, then my script is completed.


But I think, there's no one to sort my problem here.

 

Anyway, thanks for all your SUGGESTIONS.

James Gifford—NitroPress
Legend
January 11, 2025

I'll just point out that you have not once given any reason, purpose or need for this action (Have pointedly avoided doing so, even) and just gotten exasperated when you weren't handed a working answer for your purposes. Sometimes... it's not that simple and feedback on the 'why' can help steer a discussion to a productive end.

Inspiring
January 16, 2025

You could try this - I don't have files to test it on but added some extra functionality that should work

 

Again I'm not the best at this - ceratinly not working blind as nothing to test with 

 

function convert2CMYK() {
    var doc = app.activeDocument;
    var selection = doc.selection;

    if (!selection || selection.length === 0) {
        // No selection, process all images in the document
        var links = doc.links;
        for (var i = 0; i < links.length; i++) {
            var link = links[i];
            if (link.status === LinkStatus.NORMAL) {
                var image = link.parent;
                if (image.constructor.name === "Image" && image.space === "RGB") {
                    processImage(link);
                }
            }
        }
    } else {
        // Process selected items regardless of shape
        for (var j = 0; j < selection.length; j++) {
            var selectedItem = selection[j];
            if (selectedItem.constructor.name === "Image") {
                var selectedLink = selectedItem.itemLink;
                if (selectedLink && selectedLink.status === LinkStatus.NORMAL && selectedItem.space === "RGB") {
                    processImage(selectedLink);
                }
            } else if (selectedItem.images && selectedItem.images.length > 0) {
                for (var k = 0; k < selectedItem.images.length; k++) {
                    var nestedImage = selectedItem.images[k];
                    var nestedLink = nestedImage.itemLink;
                    if (nestedLink && nestedLink.status === LinkStatus.NORMAL && nestedImage.space === "RGB") {
                        processImage(nestedLink);
                    }
                }
            }
        }
    }

    UpdateAllOutdatedLinks();

    //===================== FUNCTIONS ===============================
    function processImage(link) {
        var newPath = DuplicateAndRenameFile(link.filePath);
        var profile = getCMYKProfile();
        if (profile) {
            CreateBridgeTalkMessage(newPath, profile);
            RelinkFile(link, newPath);
        } else {
            // alert("No CMYK profile selected. Conversion canceled.");
        }
    }

    function CreateBridgeTalkMessage(imagePath, profile) {
        var bt = new BridgeTalk();
        bt.target = "photoshop";
        bt.body =
            "(function() {" +
            "    var psDoc;" +
            "    app.displayDialogs = DialogModes.NO;" +
            "    psDoc = app.open(new File('" + imagePath + "'));" +
            "    if (psDoc) {" +
            "        psDoc.convertProfile('" + profile + "', Intent.RELATIVECOLORIMETRIC, true);" +
            "        psDoc.save();" +
            "        psDoc.close(SaveOptions.SAVECHANGES);" +
            "    }" +
            "    app.displayDialogs = DialogModes.ALL;" +
            "})();";

        bt.onError = function (errObj) {
            // alert("Error in BridgeTalk: " + errObj.body);
        };

        bt.onResult = function () {
            alert("Image successfully converted to CMYK!");
        };

        bt.send(30);
    }

    function UpdateAllOutdatedLinks() {
        var link, c;
        for (c = doc.links.length - 1; c >= 0; c--) {
            link = doc.links[c];
            if (link.status == LinkStatus.LINK_OUT_OF_DATE) link.update();
        }
    }

    function DuplicateAndRenameFile(filePath) {
        var file = new File(filePath);
        var folderPath = file.path;
        var fileName = file.name;
        var fileExtension = fileName.substring(fileName.lastIndexOf("."));
        var baseName = fileName.substring(0, fileName.lastIndexOf("."));
        var newFileName = baseName + "_C" + fileExtension;
        var newFilePath = folderPath + "/" + newFileName;

        var newFile = new File(newFilePath);
        if (file.copy(newFilePath)) {
            return newFilePath; // Return the path of the duplicated file
        } else {
            alert("Failed to duplicate and rename file: " + filePath);
            return filePath;
        }
    }

    function RelinkFile(link, newPath) {
        var newFile = new File(newPath);
        if (newFile.exists) {
            link.relink(newFile);
            link.update();
        } else {
            alert("Failed to relink file: " + newPath);
        }
    }

    function getCMYKProfile() {
        var profiles = [
            "Coated FOGRA39 (ISO 12647-2:2004)",
            "Coated FOGRA27 (ISO 12647-2:2004)",
            "Coated GRACoL 2006 (ISO 12647-2:2004)",
            "ISO Web Coated",
            "ISOnewspaper26v4",
            "Japan Color 2001 Coated",
            "Japan Color 2001 Uncoated",
            "Japan Color 2002 Newspaper",
            "Japan Color 2003 Web Coated",
            "Japan Web Coated (Ad)",
            "U.S. Sheetfed Coated v2",
            "U.S. Sheetfed Uncoated v2",
            "U.S. Web Coated (SWOP) v2",
            "U.S. Web Uncoated v2",
            "Uncoated FOGRA29 (ISO 12647-2:2004)",
            "US Newsprint (SNAP 2007)",
            "Web Coated FOGRA28 (ISO 12647-2:2004)"
        ];

        var profileName = showDropdown(profiles);
        return profileName;
    }

    function showDropdown(profiles) {
        var dialog = new Window("dialog", "Select CMYK Profile");
        dialog.orientation = "column";
        var dropdown = dialog.add("dropdownlist", undefined, profiles);
        dropdown.selection = 0;
        dialog.add("button", undefined, "OK", { name: "ok" });

        if (dialog.show() == 1) {
            return dropdown.selection.text;
        } else {
            return null;
        }
    }
}

convert2CMYK();

What I'm trying to do

 

Selection Handling:

  • Full Document Processing: Processes all images in the document if no selection is made.
  • Selected Items: Processes only selected images or nested images within selected objects.

Image Conversion:

  • RGB Detection: Checks if the image is in RGB colour space before converting.
  • Photoshop Integration: Uses BridgeTalk to send instructions to Photoshop for profile conversion.

File Management:

  • File Duplication: Creates a duplicate file with _C appended to the filename before conversion, preserving the original.
  • Relinking: Relinks the duplicated and converted CMYK file back to the InDesign document.

CMYK Profile Selection:

  • Dropdown Interface: Allows users to select a CMYK profile dynamically using a dropdown menu.
  • Profile List: Provides a comprehensive list of predefined CMYK profiles.

Link Management:

  • Link Status Check: Ensures links are active and normal before processing.
  • Outdated Link Update: Updates any outdated links in the document after processing.

Error Handling:

  • Error Messages: Alerts users about issues such as failed duplication, relinking, or BridgeTalk errors.
  • Fallbacks: Prevents further steps if prerequisites like CMYK profile selection fail.

Additional Features:

  • BridgeTalk Customisation: Allows integration with Photoshop for automated conversion without user intervention.
  • User Feedback: Displays alerts to confirm the successful conversion of images.

 


Hi Eugene,

 

You have given me my code in return, there's no difference, the script is pulling the profile's list manually instead of auto-fetching.  I think this is not a doable task, so let's close this chapter here.

 

Anyway, thanks everyone for your time and suggestions!

Community Expert
January 11, 2025

As mentioned already by others

 

The best way to do this is a Batch Convert in Photoshop with an action - which can be performed on an entire folder of images. 

 

What I do is record the conversion in Photoshop, but save to a different folder say called CMYK images. 

Then you can Relink all images using the Links Panel sub menu - there's an option to point to a folder, so you don't have to relink all the images one by one. 

Keeping the same file name and format etc. 

 

What you'll have trouble with is things like PNG which are RGB only - so you'll need to batch convert these to TIFF or PSD format

Then you can use the Links Panel to relink to a new file Format which is in the Sub Menu - quite useful

 

This is far quicker and far more reliable. 

 

All this requires for your images to be located in the same folder to do the Batch Conversion. 

If the images are spread out over multiple folders then that makes it harder. 

 

I've had it before for a magazine where the author supplied all the images in folders Page 1>bunch of images Page 2>Bunch of images 

In each folder for each page they were called Image01.tif, Image02.tif --- in each folder the same file names. 

It was a nightmare. 

 

Anyway 

If the client wants all the images in CMYK in Indesign that's understandable, as you can see the CMYK colour directly in InDesign and manage the CMYK values. If you have as RGB and export to CMYK the values may shift depending (they still can with CMYK to CMYK --- but that's their problem)

I understand if they need complete control over CMYK values. 

 

A script would be good if the images are stored all over the place in different folders. 

But if not - then the Photoshop Batch Action is the easiest solution. 

 

Let us know if you need help setting it up. 

 

If you're still looking for a script maybe we can help with that - understandably if files are not all centrally located.

Mike Witherell
Community Expert
Community Expert
January 10, 2025

The script you cite on Kasyan's site is an OK thing to do, but your request is a technically wrong thing to do. Neither is really necessary when you follow a holistic color management method from Photoshop on downstream to InDesign and on downstream to exporting the PDF file. Let the PDF-export do the conversion.

Mike Witherell
James Gifford—NitroPress
Legend
January 10, 2025

And with less snark intended, I think this is a case where it really should be discussed with the client. Yes, there are times you do what you're told and what they want, but unless there's a very specific reason for this request, a little "expert correction" back up the chain is not out of line.

Willi Adelberger
Community Expert
Community Expert
January 10, 2025

Leave the images in InDesign as RGB. Convert the images with the PDF export to their output profile. There is no. Eed to convert them extra. 

Inspiring
January 10, 2025

Thanks, Willi, I know about this. But I also need this script as part of my job requirement. The client insist the images to be CMYK in InDesign itself. So, a workaround with JavaScript would be much appreciated.

Community Expert
January 10, 2025

It seems like a Photoshop batch process would accomplish this, and make more sense to convert images prior to placing in Indesign.