Search code examples
photoshopphotoshop-script

Photoshop: Script to convert jpeg to 16 bit on open


Using Photoshop, I want to automatically convert all opened JPEGs to 16 bit. I currently do this manually before making any edits to them, and I figure I should be able to automate this step so it happens automatically.

I've learnt that I can run scripts on events using Scripts Event Manager, so I know how to run a script on document open.

But unfortunately I don't know how to write the Photoshop script itself.

Can anyone assist with how I'd write a script that detects whether the current document is RGB/8bit, and if it is, converts it to RGB/16bit, automatically on document open?

Alternatively, if there's any easier way to do this using Actions or something, that'd be good to know.


Solution

  • After deciding to not be lazy and look into it myself... it turns out it is not difficult.

    This script will convert the active document to 16bit if it ends in *.jpg or *.jpeg, is an RGB document, and is 8 bit.

    Changing these if conditions is easy as you can see below.

    Save it as a .js or .jsx file.

    Then to run this script automatically on file open, use FileScriptsScript Events Manager and choose Open Document as the Photoshop Event, then select or browse for your script.

    if(
        /jp.?g$/i.test(activeDocument.name)
        && activeDocument.mode == DocumentMode.RGB
        && activeDocument.bitsPerChannel == BitsPerChannelType.EIGHT
    ) {
        activeDocument.bitsPerChannel = BitsPerChannelType.SIXTEEN;
    }