Copy link to clipboard
Copied
Is there a script or action that could batch a folder of images and determine which files have transparency and which do not?
These are layered product shots. In some files a white bottom fill layer is turned on beneath the shadow layer. In some files it is not on, or not present, and these would be the images with transparency. However, that white fill layer is sometimes an empty layer filled with white, sometimes a solid color adjustment layer, and not consistently named, so I don't thin one could simply check for the presence of that layer.
My goal is to know which files have the transparency without having to open each one to find out. There are hundreds of them, and they are heavy files.
PS CC, Mac, sRGB
As I write this I have a thought. I suppose I could duplicate the files, then run an action on the dupes to place a solid fill layer at the bottom (of a color other than while - say, red) and via the finder or bridge see which ones have a red background and which ones don't.
Any better ideas? Would really prefer not to work on proxy files requiring me to cross reference. Would be cool if there were a way to have the action/script separate into folders, or change metadata, or something to make an easy sort job of those that do and don't have transparency.
Copy link to clipboard
Copied
You may want to do a search over at
Copy link to clipboard
Copied
Moving to Photoshop Scripting
Copy link to clipboard
Copied
If you saved PSD with maximum compatibility then you can hold left Alt + Shift and you can load composite data instead layers. This will open file much much faster. But it seems to be wired with keys and I don't know how to script it. So you could use brick as workaround 😄
In channels class is Alpha Channel for transparent pixels. It has index -1 in action reference. But values doesn't makes sense to me.
Alternatively you can load layer transparency into selection, then switch into quick mask mode and read histogram for quick mask channels. It shows me correct values.
Or there is possibility to build PSD binary parser. Composite data are last block in PSD: Adobe Photoshop File Formats Specification
This is fastest solution because you read only data you need and you don't need open PSD file. But it is most difficult.
Copy link to clipboard
Copied
Not opening the file is unlikely to succeed. If you open it, you can use a script to determine if there is transparency.
var transp = true;
var d = new ActionDescriptor();
var r = new ActionReference();
r.putProperty( charIDToTypeID( "Chnl" ), charIDToTypeID( "fsel" ) );
d.putReference( charIDToTypeID( "null" ), r );
var r2 = new ActionReference();
r2.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Chnl" ), charIDToTypeID( "Trsp" ) );
r2.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Mrgd" ) );
d.putReference( charIDToTypeID( "T " ), r2 );
try {
executeAction( charIDToTypeID( "setd" ), d, DialogModes.NO );
activeDocument.selection.invert();
try { activeDocument.selection.bounds; } catch(e) { transp = false; }
}
catch(e) { transp = false; }
activeDocument.selection.deselect();
if (transp) alert("Has transparency");
else alert("No transparency");
Copy link to clipboard
Copied
Although I can’t script, I can sometimes hack them in a Dr Frankenstein fashion… The following code modified from r-bin (post #4) will add a description metadata value of “Transparent” which can be used in say Adobe Bridge to isolate the images using the Find command. The script can be recorded into an action and used in Automate/Batch or Image Processor to batch apply the metadata to the images. Note that any existing description metadata entry will be overwritten, with a little more work I’m sure the value could be appended or a different field such as subject/keywords could be used.
More on installing scripts here:
Prepression: Downloading and Installing Adobe Scripts
var doc = activeDocument;
var transp = true;
var d = new ActionDescriptor();
var r = new ActionReference();
r.putProperty( charIDToTypeID( "Chnl" ), charIDToTypeID( "fsel" ) );
d.putReference( charIDToTypeID( "null" ), r );
var r2 = new ActionReference();
r2.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Chnl" ), charIDToTypeID( "Trsp" ) );
r2.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Mrgd" ) );
d.putReference( charIDToTypeID( "T " ), r2 );
try {
executeAction( charIDToTypeID( "setd" ), d, DialogModes.NO );
activeDocument.selection.invert();
try { activeDocument.selection.bounds; } catch(e) { transp = false; }
}
catch(e) { transp = false; }
activeDocument.selection.deselect();
if (transp) doc.info.caption += "Transparent"
Although I removed the “else” line (is there a null option?) – no errors were generated on the files that did not contain transparency. Or one could of course add a description value of “White BG” or something for the else condition.
Copy link to clipboard
Copied
I do not quite understand your English.)
Error
executeAction (charIDToTypeID ("setd"), d, DialogModes.NO);
will be, when there is only Background.
P.S. My English is a Google translator )
Copy link to clipboard
Copied
Yet another option is a combined approach using both scripts and ExifTool. One could use the Photoshop script from post #15 to batch write metadata to the images, then use ExifTool to conditionally move matching images to folders based on the metadata written from Photoshop.
Copy link to clipboard
Copied
You can use the move_file() function from this post To move files and folders
to move files to the desired folder. And you do not need to create these folders.)
Copy link to clipboard
Copied
You could try script for Bridge. It does not open document and it read image pixels.
$.hiresTimer
#target bridge
$.memCache = 20000000;
$.gc();
var fle = new File(Folder.desktop + '/sample-file.psd' );
reading(new BitmapData(fle, true))
function reading(v) {
height = v.height;
width = v.width;
j = 0;
i = 0;
r = new Array(height);
c = new Array(width);
for(; j < height; j++) {
for(i=0; i < width; i++) {
c = new Color(v.getPixel(i, j)).toString();
}
//c = (' '+c.toString());
r
= c.slice(); if(j==1){
if(r[0]===r[1]){
alert("same");
}
}
}
var txt = File(fle.toString().slice(0, -3) + 'txt');
txt.open('w');
txt.write(r.toSource());
txt.close()
}
$.writeln($.hiresTimer/1000 + " ms");
This reads sample-file.psd inside desktop folder and saves data as .txt file. So you would modify input/output files.
Data are in #AARRGGBB format so you need only first two numbers.
I strongly recommend stop "for" loop when you find first transparent pixel and check next image.
Copy link to clipboard
Copied
There are many possibilities using an ExifTool conditional based around transparency. Command line code examples for the Mac OS follows (Windows users would simply swap around the double/single straight quotes and use appropriate file paths). As these commands overwrite the original files without making any backups, work on copies and or use at your own risk.
To recursively move files matching the if condition to a new folder titled Transparent Images in all sub folders under the top-level input folder on the desktop of the user Bob:
exiftool -overwrite_original -r -if '$AlphaChannelsNames eq "Transparency"' -directory=%d'Transparent Images' '/Users/bob/Desktop/top level input folder'
Alternatively, to recursively apply metadata such as a Bridge label of Review in all folders/files under the top-level input folder on the desktop of the user Bob:
exiftool -overwrite_original -r -if '$AlphaChannelsNames eq "Transparency"' -label='Review' '/Users/bob/Desktop/top level input folder'
Or to recursively apply metadata such as a Bridge rating of five stars in all folders/files under the top-level input folder on the desktop of the user Bob:
exiftool -overwrite_original -r -if '$AlphaChannelsNames eq "Transparency"' -rating='5' '/Users/bob/Desktop/top level input folder'
Copy link to clipboard
Copied
This is amazing work, Stephen. Does it work on closed files and/or can it be batched?
Can someone help a noob and tell me where to place this code and how to run it? What file, what folder, what program, etc?
FWIW, I'm probably most interested in option #1, moving to folders, but any of the three should be fine.
Copy link to clipboard
Copied
Download and install ExifTool from the link provided in my previous post.
Open Terminal.app and type/paste in the following code (ensure that straight quotes don’t become curly):
exiftool -r -if '$AlphaChannelsNames eq "Transparency"' -directory=%d'Transparent Images'
Then type a word space…
Finally, drag the parent/top level folder from the Finder into the Terminal.app window to populate the path to the folder.
Press enter/return to run.
The command will batch process all files and folders under the top level folder. It will create a new folder within each folder titled “Transparent Images” and move all files with transparency into this folder.
Further commands can be added to only process specific file types, such as -ext .psd or to ignore specific named sub-folder paths.
Getting started: Command-line ExifTool in Windows
(it is also pretty much the same for the Mac OS)
Copy link to clipboard
Copied
It's cool.
Only in my opinion this will work only for PSD files and which are saved in compatibility mode
upd. And there are no other alpha channels
Copy link to clipboard
Copied
You are indeed correct r-bin – I did not test for alpha channels or maximum compatibility off, which will fail. :[
It does work with layered TIFF files though! :]
Time permitting, I’ll see if I can come up with a better command or perhaps multiple pass commands will be required.
A Bridge or Photoshop script is still the best option for most users, however ExifTool has saved me so many times that it is hard to ignore (not to mention that I can’t write scripts).
EDIT:
Files with maximum compatibility off can be moved to a specific folder for manual checking using this command:
exiftool -r -if '$HasRealMergedData eq "No"' -directory=%d'Max Compatibility Off'
Copy link to clipboard
Copied
It does work with layered TIFF files though! :]
It's strange. I used ExifToolGUI.exe instead of the command line and found no AlphaChannelsNames tag in the TIFF file with transparency.
Copy link to clipboard
Copied
The perils of using the GUI? I am using ExifTool version 10.86:
exiftool -a -G1 -s PathToFile
exiftool -Photoshop:AlphaChannelsNames PathToFile
Copy link to clipboard
Copied
ExifToolVersion | : 10.89 |
FileName | : 1.tif |
Directory | : C:/A3 |
FileSize | : 6.1 MB |
FileModifyDate | : 2018:04:05 02:16:14+03:00 |
FileAccessDate | : 2018:04:05 02:16:13+03:00 |
FileCreateDate | : 2018:04:05 01:13:02+03:00 |
FilePermissions | : rw-rw-rw- |
FileType | : TIFF |
FileTypeExtension | : tif |
MIMEType | : image/tiff |
ExifByteOrder | : Little-endian (Intel, II) |
SubfileType | : Full-resolution Image |
ImageWidth | : 1920 |
ImageHeight | : 1080 |
BitsPerSample | : 8 8 8 |
Compression | : Uncompressed |
PhotometricInterpretation | : RGB |
StripOffsets | : 20236 |
Orientation | : Horizontal (normal) |
SamplesPerPixel | : 3 |
RowsPerStrip | : 1080 |
StripByteCounts | : 6220800 |
XResolution | : 72 |
YResolution | : 72 |
PlanarConfiguration | : Chunky |
ResolutionUnit | : inches |
Software | : Adobe Photoshop CC (Windows) |
ModifyDate | : 2018:04:05 02:16:13 |
XMPToolkit | : Adobe XMP Core 5.6-c142 79.160924, 2017/07/13-01:06:39 |
CreatorTool | : Adobe Photoshop CS6 (Windows) |
CreateDate | : 2018:04:05 00:57:58+03:00 |
MetadataDate | : 2018:04:05 02:16:13+03:00 |
Format | : image/tiff |
InstanceID | : xmp.iid:0d5e2523-30c0-7d4e-80cc-62f620451515 |
DocumentID | : xmp.did:29E4523C5338E811BDA2C8B0923A90D4 |
OriginalDocumentID | : xmp.did:29E4523C5338E811BDA2C8B0923A90D4 |
HistoryAction | : created, saved, saved, converted, derived, saved, saved |
HistoryInstanceID | : xmp.iid:29E4523C5338E811BDA2C8B0923A90D4, xmp.iid:32E4523C5338E811BDA2C8B0923A90D4, xmp.iid:CBD7B0ED5438E811BDA2C8B0923A90D4, xmp.iid:CCD7B0ED5438E811BDA2C8B0923A90D4, xmp.iid:0d5e2523-30c0-7d4e-80cc-62f620451515 |
HistoryWhen | : 2018:04:05 00:57:58+03:00, 2018:04:05 01:09:29+03:00, 2018:04:05 01:13:02+03:00, 2018:04:05 01:13:02+03:00, 2018:04:05 02:16:13+03:00 |
HistorySoftwareAgent | : Adobe Photoshop CS6 (Windows), Adobe Photoshop CS6 (Windows), Adobe Photoshop CS6 (Windows), Adobe Photoshop CS6 (Windows), Adobe Photoshop CC (Windows) |
HistoryChanged | : /, /, /, / |
HistoryParameters | : from application/vnd.adobe.photoshop to image/tiff, converted from application/vnd.adobe.photoshop to image/tiff |
DerivedFromInstanceID | : xmp.iid:CBD7B0ED5438E811BDA2C8B0923A90D4 |
DerivedFromDocumentID | : xmp.did:29E4523C5338E811BDA2C8B0923A90D4 |
DerivedFromOriginalDocumentID : xmp.did:29E4523C5338E811BDA2C8B0923A90D4
ColorMode | : RGB |
CurrentIPTCDigest | : c75d17e574b56ef5dbbe3994c0e9795c |
CodedCharacterSet | : UTF8 |
ApplicationRecordVersion | : 0 |
IPTCDigest | : c75d17e574b56ef5dbbe3994c0e9795c |
DisplayedUnitsX | : inches |
DisplayedUnitsY | : inches |
PrintStyle | : Centered |
PrintPosition | : 0 0 |
PrintScale | : 1 |
GlobalAngle | : 120 |
GlobalAltitude | : 30 |
URL_List | : |
SlicesGroupName | : 1 |
NumSlices | : 1 |
PixelAspectRatio | : 1 |
PhotoshopThumbnail | : (Binary data 1023 bytes, use -b option to extract) |
HasRealMergedData | : Yes |
WriterName | : Adobe Photoshop |
ReaderName | : Adobe Photoshop CC |
ColorSpace | : Uncalibrated |
ExifImageWidth | : 1920 |
ExifImageHeight | : 1080 |
ImageSourceData | : (Binary data 150868 bytes, use -b option to extract) |
ImageSize | : 1920x1080 |
Megapixels | : 2.1 |
Copy link to clipboard
Copied
What command did you enter into the GUI or the command line? Have you tried the following to display duplicate tags (-a), sorted by group (-G1) and actual tag name (-s) rather than description?
-a -G1 -s
Copy link to clipboard
Copied
What command did you enter into the GUI or the command line? Have you tried the following to display duplicate tags (-a), sorted by group (-G1) and actual tag name (-s) rather than description?
-a -G1 -s
This was the output of the command line on winx86
exiftool -a -G1 -s
On win x64 it looks like this (strange)
[ExifTool] ExifToolVersion : 10.89
[System] FileName : 1.tif
[System] Directory : C:/A3
[System] FileSize : 6.1 MB
[System] FileModifyDate : 2018:04:05 02:16:16+03:00
[System] FileAccessDate : 2018:04:05 10:56:55+03:00
[System] FileCreateDate : 2018:04:05 10:56:55+03:00
[System] FilePermissions : rw-rw-rw-
[File] FileType : TIFF
[File] FileTypeExtension : tif
[File] MIMEType : image/tiff
[File] ExifByteOrder : Little-endian (Intel, II)
[File] CurrentIPTCDigest : c75d17e574b56ef5dbbe3994c0e9795c
[IFD0] SubfileType : Full-resolution Image
[IFD0] ImageWidth : 1920
[IFD0] ImageHeight : 1080
[IFD0] BitsPerSample : 8 8 8
[IFD0] Compression : Uncompressed
[IFD0] PhotometricInterpretation : RGB
[IFD0] StripOffsets : 20236
[IFD0] Orientation : Horizontal (normal)
[IFD0] SamplesPerPixel : 3
[IFD0] RowsPerStrip : 1080
[IFD0] StripByteCounts : 6220800
[IFD0] XResolution : 72
[IFD0] YResolution : 72
[IFD0] PlanarConfiguration : Chunky
[IFD0] ResolutionUnit : inches
[IFD0] Software : Adobe Photoshop CC (Windows)
[IFD0] ModifyDate : 2018:04:05 02:16:13
[IFD0] ImageSourceData : (Binary data 150868 bytes, use -b option to extract)
[XMP-x] XMPToolkit : Adobe XMP Core 5.6-c142 79.160924, 2017/07/13-01:06:39
[XMP-xmp] CreatorTool : Adobe Photoshop CS6 (Windows)
[XMP-xmp] CreateDate : 2018:04:05 00:57:58+03:00
[XMP-xmp] MetadataDate : 2018:04:05 02:16:13+03:00
[XMP-xmp] ModifyDate : 2018:04:05 02:16:13+03:00
[XMP-dc] Format : image/tiff
[XMP-xmpMM] InstanceID : xmp.iid:0d5e2523-30c0-7d4e-80cc-62f620451515
[XMP-xmpMM] DocumentID : xmp.did:29E4523C5338E811BDA2C8B0923A90D4
[XMP-xmpMM] OriginalDocumentID : xmp.did:29E4523C5338E811BDA2C8B0923A90D4
[XMP-xmpMM] HistoryAction : created, saved, saved, converted, derived, saved, saved
[XMP-xmpMM] HistoryInstanceID : xmp.iid:29E4523C5338E811BDA2C8B0923A90D4, xmp.iid:32E4523C5338E811BDA2C8B0923A90D4, xmp.iid:CBD7B0ED5438E811BDA2C8B0923A90D4, xmp.iid:CCD7B0ED5438E811BDA2C8B0923A90D4, xmp.iid:0d5e2523-30c0-7d4e-80cc-62f620451515
[XMP-xmpMM] HistoryWhen : 2018:04:05 00:57:58+03:00, 2018:04:05 01:09:29+03:00, 2018:04:05 01:13:02+03:00, 2018:04:05 01:13:02+03:00, 2018:04:05 02:16:13+03:00
[XMP-xmpMM] HistorySoftwareAgent : Adobe Photoshop CS6 (Windows), Adobe Photoshop CS6 (Windows), Adobe Photoshop CS6 (Windows), Adobe Photoshop CS6 (Windows), Adobe Photoshop CC (Windows)
[XMP-xmpMM] HistoryChanged : /, /, /, /
[XMP-xmpMM] HistoryParameters : from application/vnd.adobe.photoshop to image/tiff, converted from application/vnd.adobe.photoshop to image/tiff
[XMP-xmpMM] DerivedFromInstanceID : xmp.iid:CBD7B0ED5438E811BDA2C8B0923A90D4
[XMP-xmpMM] DerivedFromDocumentID : xmp.did:29E4523C5338E811BDA2C8B0923A90D4
[XMP-xmpMM] DerivedFromOriginalDocumentID : xmp.did:29E4523C5338E811BDA2C8B0923A90D4
[XMP-photoshop] ColorMode : RGB
[IPTC] CodedCharacterSet : UTF8
[IPTC] CodedCharacterSet : UTF8
[IPTC] ApplicationRecordVersion : 0
[Photoshop] IPTCDigest : c75d17e574b56ef5dbbe3994c0e9795c
[Photoshop] XResolution : 72
[Photoshop] DisplayedUnitsX : inches
[Photoshop] YResolution : 72
[Photoshop] DisplayedUnitsY : inches
[Photoshop] PrintStyle : Centered
[Photoshop] PrintPosition : 0 0
[Photoshop] PrintScale : 1
[Photoshop] GlobalAngle : 120
[Photoshop] GlobalAltitude : 30
[Photoshop] URL_List :
[Photoshop] SlicesGroupName : 1
[Photoshop] NumSlices : 1
[Photoshop] PixelAspectRatio : 1
[Photoshop] PhotoshopThumbnail : (Binary data 1023 bytes, use -b option to extract)
[Photoshop] HasRealMergedData : Yes
[Photoshop] WriterName : Adobe Photoshop
[Photoshop] ReaderName : Adobe Photoshop CC
[ExifIFD] ColorSpace : Uncalibrated
[ExifIFD] ExifImageWidth : 1920
[ExifIFD] ExifImageHeight : 1080
[Composite] ImageSize : 1920x1080
[Composite] Megapixels : 2.1
Command
exiftool -Photoshop: AlphaChannelsNames
did not output anything
The file itself
Copy link to clipboard
Copied
Ah, when I saved the TIFF files I included the option to save transparency info into the TIFF, whereas you did not.
So if this option is not used, then TIFF files will not be recognised as transparent outside of Photoshop when they are transparent in Photoshop. Not a big deal if TIFF are not being used anyway, but something to keep in mind.
Copy link to clipboard
Copied
OK, incremental progress with the ExifTool conditionals.
The best that I can do for now is a 2 step process.
Step 1: Move PSD files with Max Compatibility Off to a new folder and manually sort which have a visible back layer vs. those with transparency.
exiftool -r -if '$HasRealMergedData eq "No"' -directory=%d'Max Compatibility Off'
Step 2: Move all transparent files to a new folder, whether or not they have alphas or not.
exiftool -r -if '$AlphaChannelsNames =~ /Transparency/' -directory=%d'Transparent Images'
_______________________
OK, here is a combination command that only requires a single step/run:
exiftool -if '$HasRealMergedData eq "No"' -directory=%d'Max Compatibility Off' -execute -if '$AlphaChannelsNames =~ /Transparency/' -directory=%d'Transparent Images' -common_args -r
Copy link to clipboard
Copied
@Stephen_A_Marsh, did you ever find out if there is a way to identify with ExifTool if a PSB/PSD image with Maximize Compatibility turned off has transparency or not?
Based on my testing of two files (attached), both with Maximize Compatibility off (one with transparency and the other without), it doesn't appear Adobe/ExifTool returns anything for transparency under -AlphaChannelsNames, or anywhere else that I can see. In the example files,
-LayerRectangles can help give a better clue, but it's not foolproof as there could be transparency within that -LayerRectangles doesn't account for.
Check out my post here on the ExifTool forum for more details.
If you've come across anything that may help Phil identify this, please LMK. (I've also made an inquiry with Adobe Enterprise Support.) Cheers!
Copy link to clipboard
Copied
@Chris.S – No, I didn't, as ExifTool is reading the metadata and not the raster data.
Opening the image data in Photoshop, a script can determine this: