I am trying to automate a save function based on if a file contains transparent pixels or not. If a file contains no transparent pixels then I will save the file as an EPS with JPEG compression, and if the file does contain transparency I will have the script save the file as a TIFF retaining transparency in its save options.
I suppose I can present the user with a prompt, but I’d rather the script detect the transparent pixels and no how to proceed.
Just wanted to check how you’re defining ‘transparent pixels’ because there are a few variations?
For example, when you open a new document you can select a transparent background, or you could create a transparency effect by setting a layer opacity.
Hi TecNik,
What it boils down to his how the file will appear when it is placed into InDesign. For example the Photoshop file prior to being saved might contain multiple layers, each opaque with various transparency or masks, etc. (But if the composite of all those layers is not transparent then I want the script to save it as a flattened EPS.)
Assume the file is placed into an indd document. if any part of the InDesign’s background appears visible beneath the placed Photoshop file, then that file is transparent and the script should have saved it as a TIFF with transparency.
Presently I have the script creating 4 color samplers to test 3 corners and the center of the document. If any one of those color samplers fails to retrieve pixel color data then I know the the file is transparent for my intents and purposes”and I know to save that file as a transparent TIFF. This works for most instances, but it doesn’t account for files that are intended to be semi transparent since the color samplers will retrieve pixel data. Plus, the color sampler method is a bit sluggish”about a 1.5 second delay.
One thing I did notice, when creating a couple of sample files in PS, was that when creating a new file with a transparent background there isn’t a layer called ‘Background’.
When ‘getting the properties’ of the file, without a ‘background’ layer, the property ‘background layer’ is missing. However, when ‘getting the properties’ of a document that does, contain a background layer, the property ‘background layer’ is present and it has a number of attributes assigned to it.
Is this something you could test for?
Just one other little thing, to speed up processing I sometimes close down the application’s window as small as it will go, and switch off all panels, so the screen redraw time is cut down. It used to make a difference when I was running PS Javascript actions on a PC.
Ah. very interesting about hiding all panels to improve redraw speed. Thank you, I am going to try that.
As for Background layer, yes I presently test for a base layer being both visible and named Background. If both those conditions are true then I got right to saving as EPS with no need for color sampling. It’s the other files I am not concerned with. Because it is very possible for a file to start with a transparent background with a base layer called “Layer 1” and then the operator fills that layer with pixels