I cannah give yeh any more pixels, Cap'n!
May 10, 2011 11:12 AM   Subscribe

Anyone know of a way to automate changing transparency of shapes (polygons?) in an .eps file? Anyone modified anything about an .eps file in a text editor?

I don't know vectorized graphics too well, so forgive if I mess up the terminology.

I'm saving Matlab figures that are supposed to include partially transparent shapes as vectorized .eps files. Problem is, there's a known bug in Matlab's renderer that nukes transparency, so everything comes out as fully opaque in the resulting .eps. (Bitmaps come out fine, but that's no good for my purposes.)

If I were doing one or two figures for a paper, I'd go in and change the transparency in Illustrator. Thing is, I'm making automatic daily reports that include dozens, even hundreds, of .eps plots.

I'm curious if there's a way to automate this change with a bash or Python script. .eps files are just binary text, but they're super-long. I can't for the life of me find my shapes or their transparency settings. The good thing is that I want to change all the solid polygons in the figure (the rest is lines and text), so if I could make the transparency change to everything with a fill, I'd be all set.

I realize that's not super clear-- the tl;dr version is that this is what Matlab spits out, and this is what we want. I made that exemplar change in Illustrator, but I want a method of modifying dozens of .eps files at once.

Thanks!

This is really a shot in the dark. I don't expect this to be possible/easy; the easy solutions are obviously to make it a bitmap (yuck) or wait for Mathworks to fix the bug (double yuck).
posted by supercres to Computers & Internet (6 answers total) 1 user marked this as a favorite
 
Response by poster: Just realized that some browsers may have trouble with the .eps files linked. Here they are as .pdf (and smaller in filesize to boot):

This is what Matlab spits out (PDF) and this is what we want (PDF).
posted by supercres at 11:19 AM on May 10, 2011


huh...I dunno about the more elegant solution you're proposing (which would be AWESOME), but there are ways to script that kind of post-processing in Illustrator or Photoshop (probably the GIMP, too, if you're on a tighter budget).

Here's a javascript example for Illustrator: http://forums.adobe.com/thread/506233?tstart=-2

There's the beginnings of an explanation here for the GIMP: http://gimpchat.com/viewtopic.php?f=8&t=733&start=0
posted by ivan ivanych samovar at 11:20 AM on May 10, 2011


Best answer: Manipulating the eps directly is going to be extra difficult because eps files don't support transparency. The transparent eps file is actually flattened, which is a lot more difficult than just setting an alpha value for fills - new polygons are created for the overlapping areas and colored to look like they are transparent. That's one reason the transparent eps is almost 50 times the size of the original.

PDF does support alpha, but distilling all the eps files and tweaking the resulting PDFs may not be straightforward either.

Ivan's suggestion for scripting Illustrator is probably your best bet.
posted by and for no one at 11:37 AM on May 10, 2011 [1 favorite]


Best answer: Yeah, as and for no one indicates, transparency in EPS files isn't a given thing. It might be that Matlab is simply creating valid Level 1 or Level 2 PostScript inside the EPS files - and so is under no obligation to honor the transparency values. I believe Level 3 PostScript adds support for this type of transparency.

A useful trick in this type of situation is to try all the different vector formats you can get as output. What other vector formats can MatLab export? Are there plugins for direct-to-PDF, or SVG perhaps?
posted by krilli at 1:12 PM on May 10, 2011 [1 favorite]


Response by poster: Thanks for three excellent answers that got me closer and closer to success.

Thanks to AFNO, I discovered that EPS files wouldn't work, since it doesn't preserve the transparency. I found a function that can export SVG from Matlab, on krilli's suggestion. Those files do include the transparency. (Matlab can't do vectorized PDFs with transparency; if there are alpha values below one, it reverts to a bitmap renderer.)

Now I just have to get them into LaTeX, probably as PDFs via Inkscape.
posted by supercres at 3:00 PM on May 10, 2011


Inkscape uses Uniconvertor for its format conversions so i'd install that and and script it from the command line. You mention python and bash so if you're on a Debian system it's just "apt-get install uniconvertor"

As for your original question: EPS is a format unsuited to direct manipulation. I'd convert EPS to SVG, tweak the SVG with conventional XML tools, and then push it back to EPS. In practice you may have use PDF as an interchange format because there may not be direct converters. E.g. http://frotz.homeunix.org/scripts/eps2svg
posted by holloway at 6:04 PM on May 10, 2011


« Older Songs for Home Movies?   |   This is not who I am! Newer »
This thread is closed to new comments.