I'm looking to write a very simple program that can read through an EPS and/or AI file and detect if an opacity mask is being used and if possible the number of them in the file. Digging in to the EPS file specification I'm having trouble pinning down if there's a specific instruction I can search for in the EPS or AI code.
At first I was thinking <xmpTPg:HasVisibleTransparency>True</xmpTPg:HasVisibleTransparency>
but this can be set to true even if an opacity mask does not exist.
Can anyone with any familiarity with EPS or AI formats point me in the right direction?
Note: I am NOT looking to manipulate these files I just want to detect the existence of opacity masks.
The most fundamental problem you've got with this question is that Adobe doesn't use declarative formative (as, say, SVG is), but rather imperative ones. Postscript, at root, is a programming language for describing how to paint images, rather than what image to paint. So there's not, as part of the format itself, a completely canonical way to detect that a mask is present.
That said, particular pieces of software will use the format in consistent ways. In that situation, you can treat the explicit specification as a part of what's happening and use observed behavior of the software as the rest. So, assuming that you want to find opacity masks as they appear in Illustrator, I'd say the best way to approach this problem is see how AI saves such masks by observing its behavior. To wit, take some existing AI file without a mask and make a copy. Open the copy in AI, do exactly one operation to create a mask. Save. Now compare the before and after versions of the file. Having looked briefly at the AI file format specification, I think you'll have to do something like this regardless, because there seems to be more than one way that AI could implement such masks in its saved files.