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

delete all channels previously created by "save selection"

New Here ,
Jan 08, 2009 Jan 08, 2009
hi,

i am looking for a script that would delete all of the "extra" channels in an image that are created via "save selection" process regardless of how many there are and leave only the 4 default channels (rgb, red, blue, green). if it also flattens the image first, that would be even better. any help would be much appreciated.

thanks,

john
TOPICS
Actions and scripting
1.6K
Translate
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
Adobe
Valorous Hero ,
Jan 08, 2009 Jan 08, 2009
This should do it.

activeDocument.flatten();
activeDocument.channels.removeAll();
Translate
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
New Here ,
Jan 08, 2009 Jan 08, 2009
thanks paul!

as you can tell, i don't know anything about scripting. it was at the advice of adobe support who told me that it may or may not be possible to do this (and implying a certain astronomical level of complexity) that i posted my issue to the forum. now at the risk of further exposing my ignorance, is it easy to explain how i actually take the script content you provided and make a "script" out of it and then make it accessible to photoshop? if it is too long or complicated to explain the required steps, is there a website or literature you could refer me to to learn how to do this? sorry to be such a pest...

thanks again,

john h.
Translate
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
Guru ,
Jan 08, 2009 Jan 08, 2009
As scripts go this one is about as simple as they get. I'll let Paul explain how to save his code as a script.

But can I ask why you want to do this? If it's just to save the document to a file format that does not support layers or channels you can just saveAs and check the 'As a copy' box. Photoshop will flatten and delete the channels for you.
Translate
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
Valorous Hero ,
Jan 09, 2009 Jan 09, 2009
Thanks for the information Mike.

John here are the basics...

A script is just a text file, use a text editor such as notepad or better still ExtendSCript Toolkit that comes with Photoshop. Do not use Word as that will leave spurious characters in the file.
Depending on the version of Photoshop you have the file extension may differ. Photoshop prior to CS2 would be FileName.js otherwise FileName.jsx
You can save this file anywhere you like, but the norm is to save it:
PC:- C:/Program Files/Adobe/Adobe Photoshop CS#/Presets/Scripts/
Mac:- [hard drive]/Applications/Adobe Photoshop CS#/Presets/Scripts/

One you have the script saved, to call/use the script.
Open a document in Photoshop, then File - Scripts and select the script. This will run the script on the open document.
If you saved the script elsewhere it would be :-
File - Scripts - Browse (to where you saved the script)
You can call the script as part of an action if required by recording the File - Scripts Select script.
Hope that ok for you.
Translate
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
New Here ,
Jan 10, 2009 Jan 10, 2009
hi paul,

i finally had a chance this morning to create and test out the script and it worked perfectly! thanks so much for all of your help. it's actually something i have wanted to be able to do for years and now i finally have it... it probably doesn't seem like it, but it will be a big help. it is very intimidating for someone who has never done any scripting before to take on even such a simple task. perhaps i will have to learn more! thanks again.

kind regards,

john h.
Translate
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
New Here ,
Jan 10, 2009 Jan 10, 2009
hi michael,

sorry for the delay in responding to your question. it is a somewhat long winded explanation. i make master files in tiff format that contain many layers and numerous saved selections. i save/archive this master file in it's full uncompresses state. however, i deliver flattened versions of this file (also in tiff format) to my clients with the channels removed. i actually have never played around with the "as a copy" option and didn't realize that it performed these same functions. most of the time, i am working with a whole set of images, in which case i import them into lightroom and then export a set of tiffs and lightroom takes care of fattening and deleting the channels. however, many times, i am editing a single image and it is easier to prep it for the output version while still in photoshop rather than having to import and export a single image into and out of lightroom. i did a little experimenting with the "save a copy" feature which will handles the 2 steps that i was trying to script for but it has a coupe of drawbacks. almost always after flattening and deleting the extra channels, i also crop, crop with perspective or use image/distort/lens correction to adjust the vertical and horizontal lines (i photograph architecture primarily) and then finally, i sharpen the image. if i use the "save as copy" method it seems like i will have to either do all of these things prior to using "save as copy", or i will have to close the current master file and then re-open, process, and re-save the image. i could use the "save as copy" method after fully processing the image, but the disadvantage is that it can be very slow to use the lens correction filter on an unflattened 400mb master as opposed to a 60mb flattened image.

while both methods are an improvement over my current workflow, neither the script, nor the "save as copy" method solve my entire problem. ideally, what i would like to do is have a script that will flatten the image, delete the channels and then save the new file in the same location as the original (but not as a copy because i would still like to have the new file open so that i can perform the last few steps before closing). with the "save as copy" method it will always either save the file to the same folder that was designated when the script was recorded (if i opt for perform without dialog), or it will require me to navigate to the current desired folder each time (if i use the dialog). additionally, instead of adding "copy" to the end of the name, i want the last 7 characters of the original file name ("_master") deleted from it before saving the new file. i hope that is a clear explanation. it really only adds up to probably 5-10 seconds of difference from doing all of this manually but as i process several thousand files a year so being able to keyboard shortcut an action that would run the appropriate script would end up saving me a decent amount of time in the long run. anyway, would you happen to know if a more advanced script would be capable of all this? any additional thoughts would be much appreciated.

all the best,

john h.
Translate
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
Valorous Hero ,
Jan 10, 2009 Jan 10, 2009
You might like to try this John.
It does assume that the last 7 characters need to be removed.



#target photoshop

if(documents.length){

activeDocument.flatten();

activeDocument.channels.removeAll();

var saveFile = new File(decodeURI(activeDocument.fullName.fsName).slice(0,-11) +".tif");



if(saveFile.exists){

alert(saveFile +" already exists!");

}else{

SaveTIFF(saveFile);

}

}



function SaveTIFF(saveFile){

tiffSaveOptions = new TiffSaveOptions();

tiffSaveOptions.embedColorProfile = true;

tiffSaveOptions.alphaChannels = true;

tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW;

activeDocument.saveAs(saveFile, tiffSaveOptions, false, Extension.LOWERCASE);

}

Translate
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
New Here ,
Jan 10, 2009 Jan 10, 2009
hey paul,

thanks again... that's brilliant. it worked without a hitch. i noticed in looking at the code briefly that it appeared to be apply the lzw compression. when i double checked the file size i noticed that it was in fact compressing the file. i removed this one line from the script and it seems to run fine without it and leaves the file uncompressed (which i prefer to do). i am not that familiar with using compression except with jpegs and was of the understanding that it generally degraded the image albeit very slightly... please let me know if you think this is not accurate. also, i am assuming based on a couple of experiments (as i don't know of anyway to look it up directly) that it is saving the new file in "mac" byte order. while i am on a mac, most of my clients are on a pc (and often with older (or much older) versions of photoshop). to minimize potential problems is there a way to force it to use the 'pc' byte order, or does it have to be set that way by default because i am on a mac? i actually tried to duplicate a line of your script and revised it to read:

tiffSaveOptions.byteOrder = TIFFEncoding.TIFFIBMPC;

and about 10 other variations (....TIFFIBM, ...TIFFPC, ...IBM, ...PC, ....IBMPC, ...=IBMPC, etc.) but all of them gave me an error message.
is there a library online anywhere to see a list of legitimate commands and formatting? sorry if i am becoming a pest! i promise this is the last issue.

have a nice weekend,

john h.
Translate
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
Valorous Hero ,
Jan 10, 2009 Jan 10, 2009
No problem, here is a revised save function..


function SaveTIFF(saveFile){
tiffSaveOptions = new TiffSaveOptions();
tiffSaveOptions.embedColorProfile = true;
tiffSaveOptions.alphaChannels = true;
tiffSaveOptions.byteOrder = ByteOrder.IBM;
tiffSaveOptions.imageCompression = TIFFEncoding.NONE;
activeDocument.saveAs(saveFile, tiffSaveOptions, false, Extension.LOWERCASE);
}
Translate
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
Guru ,
Jan 11, 2009 Jan 11, 2009
LATEST
John,

When saving tiff files both LZW and and ZIP compression are 'lossless'. This is they don't affect image quality. Only using JPEG compression will.

I have one program that I use that will not read a compressed tiff otherwise I would always save tiffs with compression.

It is my understanding that all versions of Photoshop can read tiff file with either byte order. Because the byte order is one of the tiff tags, I would think that it would have to be a very poor reader that couldn't deal with either.
Translate
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