PNG to EPS with Python?

Will Stuyvesant hwlgw at hotmail.com
Sat Dec 20 11:57:35 EST 2003


> [Just]
> Have you looked at PIL yet?

No, I had not, and thank you for the suggestion Just!

WOW, PIL is amazing!  I was looking all over the internet for
"png2eps" etcetera, but my favorite programming language can do it
all with PIL!


A simple recipe to put a screenshot in your LaTeX file under Windows
(where there is no png2eps utility):

First of all you have to install PIL, get the Windows .exe and run it, 
nice and simple.
Then copy the screenshot to your Windows clipboard with
<SHIFT><ALT><PrtSc> or whatever keycombo your keyboard has.  Then
open MSPAINT.EXE, "paste" the image in there (via the Edit menu) and
"save as" a .PNG file via the File menu (for name I filled in
"myscreenshot").  Then open CMD.EXE and go to the directory where
you did save the .PNG and start the Python interpreter there.  Now
just

>>> import Image
>>> im = Image.open("myscreenshot.PNG")
>>> im.save("myscreenshot.eps")

This produces a hefty 9MB .eps file for my test screenshot, but when
you include it in your LaTeX with
\includegraphics[width=\textwidth]{myscreenshot.eps} and produce PDF
from the LaTeX (witht the MikTeX dvipdfm.exe) it amounts to only
about 90k for a PDF file with one page with the screenshot on it.
If you produce .PS from the LaTeX then it is still 9MB :-)




More information about the Python-list mailing list