Convert EPS to PNG with ImageMagick


Posted:   |  More posts about ImageMagick utilities

Coincidentally, after getting by until recently without having a good reason to try ImageMagick, I needed it again just today. I had a company logo in EPS format which I needed turned into PNG format.

Since I'm on Windows, and don't have Adobe Photoshop, this isn't a 10-second operation. At least, not until you install the right stuff. Even on Windows, however, ImageMagick knows how to call out to Ghostscript if it's installed.

The first attempt to convert produced a nice clean 52K PNG file at 2254x751. Okay, so basic conversion works:

convert myfile.eps foo.png

I wanted it to be 300 pixels wide, however, so I tried the obvious. Yes, without reading the docs... but who reads the docs the first time?

convert myfile.eps -size 300x76 foo.png

This gave the same output... Hmm. Better actually read the docs.

Okay, so -size is for when an image doesn't have known dimensions, such as can happen with certain file formats. I want -resize instead:

convert myfile.eps -resize 300x76 foo.png

That works well, except the resulting file is 60K, which is too big. Why? Explorer shows that it's a 48-bit image... rather more than I need. How to get less depth?

convert myfile.eps -resize 300x76 -depth 8 foo.png

Well, same quality but 24-bit depth and only 28K. Huh? Where did 24-bit come from when I asked for 8? It looks like the -depth option specifies per-colour depth. Using identify -verbose foo.png gives more detail than I need to learn all about that. Trying again with -depth 4 gives me as much quality as I need, at 4 bits per colour, and just over 13K.

But the file is still larger than I'd like... using "strings foo.png" shows me there is lots of metadata present in the file, leftover from the original EPS file which was apparently built in Adobe Illustrator. The -strip option will "strip the image of any profiles or comments" say the docs so let's try that:

convert myfile.eps -resize 300x76 -depth 4 -strip foo.png

That shrinks it down to only 3.8K, which is even smaller than I'd hoped for and, incidentally, 0.075% of the original EPS file size. Job done: thanks ImageMagick sponsors!

Comments powered by Disqus