[R] latex, eps graphics and transparent colors / sam2p

Michael Friendly friendly at yorku.ca
Tue May 3 14:52:21 CEST 2011


On 04/13/2011 05:06 PM, Ben Bolker wrote:
 > Thomas Lumley<tlumley<at>  uw.edu>  writes:
 >
 >>
 >> On Thu, Apr 14, 2011 at 5:30 AM,
 >>   Michael Friendly<friendly<at>  yorku.ca>  wrote:
 >>> I have a diagram to be included in latex, where all my figures are .eps
 >>> graphics (so pdflatex is not an option)
 >>
 >> You could use the pdf() device and then use pdf2ps to convert to 
PostScript.
 >
 >    Clever.
 >
 >     [snip]
 >
 >> There's now an adjustcolor() function in base R to do this.
 >>
 >
 >    That makes my solution more or less obsolete.
 >

This is a follow-up to this thread, for which I thank everyone who replied.

I could have fiddled with adjustcolor() to avoid using transparent 
colors, but instead did some tests on generating .png or .pdf files
with transparent colors and then converting to .eps.

I tried the following, in various combinations [running on ubuntu 10.02 
linux]
   input file: foo.{pdf,png}
   converters: pdf2ps, pdftopdf, convert (ImageMagick)

All of these gave really *huge* output files, by a factor of 10-20 times
the original.

Finally, I remembered (the badly named) sam2p utility,
http://pts.szit.bme.hu/sam2p/
http://code.google.com/p/sam2p/

I'm not sure what magic it uses for compression, but the results are 
quite impressive compared with the competition.

Bottom line: the combination of .pdf + sam2p seems to work best in my 
tests, below.  The result is even smaller than the input file, and
I can't tell the difference in the onscreen display.

  % ls -l foo.*
-rw-r--r-- 1 friendly staff 11794 2011-04-29 08:31 foo.pdf
-rw-r--r-- 1 friendly staff 20775 2011-04-29 08:32 foo.png
euclid: /tmp % pdf2ps foo.pdf foo-pdf2ps.eps
euclid: /tmp % pdftops foo.pdf foo-pdftops.eps
euclid: /tmp % convert foo.pdf foo-convert-pdf.eps
euclid: /tmp % convert foo.png foo-convert-png.eps
euclid: /tmp % sam2p foo.png foo-sam2p-png.eps
This is sam2p v0.47-1.
Available Loaders: PS PDF JAI PNG JPEG TIFF PNM BMP GIF LBM XPM PCX TGA.
Available Appliers: XWD Meta Empty BMP PNG TIFF6 TIFF6-JAI JPEG-JAI JPEG 
PNM GIF89a+LZW XPM PSL1C PSL23+PDF PSL2+PDF-JAI P-TrOpBb.
sam2p: Notice: PNM: loaded alpha, but no transparent pixels
sam2p: Notice: job: read InputFile: foo.png
sam2p: Notice: writeTTT: using template: l23
sam2p: Notice: applyProfile: applied OutputRule #37
sam2p: Notice: job: written OutputFile: foo-sam2p-png.eps
Success.


sam2p foo.pdf foo-sam2p-pdf.eps
This is sam2p v0.47-1.
Available Loaders: PS PDF JAI PNG JPEG TIFF PNM BMP GIF LBM XPM PCX TGA.
Available Appliers: XWD Meta Empty BMP PNG TIFF6 TIFF6-JAI JPEG-JAI JPEG 
PNM GIF89a+LZW XPM PSL1C PSL23+PDF PSL2+PDF-JAI P-TrOpBb.
gs_cmd=(gs -r72 -q -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dLastPage=1 
-sDEVICE=pnmraw -dDELAYSAFER -dBATCH -dNOPAUSE -sOutputFile=%D  -- %S)
sam2p: Notice: job: read InputFile: foo.pdf
sam2p: Notice: writeTTT: using template: l23
sam2p: Notice: applyProfile: applied OutputRule #27
sam2p: Notice: job: written OutputFile: foo-sam2p-pdf.eps
Success.
euclid: /tmp % ls -l foo*
-rw-r--r-- 1 friendly staff 1139852 2011-05-03 08:41 foo-convert-pdf.eps
-rw-r--r-- 1 friendly staff 2924149 2011-05-03 08:41 foo-convert-png.eps
-rw-r--r-- 1 friendly staff   11794 2011-04-29 08:31 foo.pdf
-rw-r--r-- 1 friendly staff 1687255 2011-05-03 08:41 foo-pdf2ps.eps
-rw-r--r-- 1 friendly staff 2775130 2011-05-03 08:41 foo-pdftops.eps
-rw-r--r-- 1 friendly staff   20775 2011-04-29 08:32 foo.png
-rw-r--r-- 1 friendly staff    8701 2011-05-03 08:44 foo-sam2p-pdf.eps
-rw-r--r-- 1 friendly staff   35926 2011-05-03 08:42 foo-sam2p-png.eps
euclid: /tmp %



More information about the R-help mailing list