25

How can I convert multiple .jpg files to .eps files on Linux?

Matthias Braun
  • 24,493
  • 16
  • 114
  • 144
Bhavneet
  • 297
  • 1
  • 4
  • 5

6 Answers6

31

When using the ImageMagick's convert, it is a good practice to use the eps2 format. This make the resulting eps file much smaller because it uses the JPEG compression algorithm (DCT).

So, to convert a.jpg to a.eps do:

convert a.jpg eps2:a.eps

This of course, can be used in a shell script, to convert multiple JPG to EPS.

Daniel Böhmer
  • 12,527
  • 5
  • 31
  • 45
user1958943
  • 451
  • 4
  • 2
  • I get the following errors when I execute : `convert: unable to open image `pic.jpg': ��. @ error/blob.c/OpenBlob/2489.` `convert: unable to open image `pic.jpg': @ error/blob.c/OpenBlob/2489.` `convert: missing an image filename `eps2:pic.eps' @ error/convert.c/ConvertImageCommand/2940.` What should I do? – Green Noob Feb 04 '15 at 04:33
  • Use imagemagick `mogrify` command instead of convert for multiple files. `mogrify -format eps3 *.png` – Raywell Sep 04 '17 at 09:21
9

You can use many tools. I recommend using convert command from ImageMagick.

#!/bin/bash

# example 1
convert myfile.jpg myfile.eps

# example 2
for file in file1.jpg file2.jpg file3.jpg; do
    echo convert "$file" $(echo "$file" | sed 's/\.jpg$/\.eps/')
done

To make example 2 run you need to remove the echo inside the for-loop. Make sure the commands it outputs are correct before removing it.

Daniel Böhmer
  • 12,527
  • 5
  • 31
  • 45
6

According to user1958943, I used the convert tool as well. However, as the eps3 format gives an even better compression with similar quality as eps2, I suggest to use

convert a.jpg eps3:a.eps

By the way, this tool also works for png files (and also others) ...

Does anybody know which compression eps3 is using?

tc88
  • 281
  • 4
  • 9
  • what is the difference between eps2 and eps3? – Nico Apr 30 '20 at 06:39
  • Version 3 is specified in appendix H of the following document: https://www-cdf.fnal.gov/offline/PostScript/PLRM2.pdf. The changes to version 2 are listed in section H.8. However, I am not sure whether you find the details about compression there... – tc88 May 02 '20 at 21:48
1

Another option is to combine jpegtopnm and pnmtops from the netpbm toolkit. This will however produce PS, not EPS.

for f in *.jpg
do
  g=`echo "$f" | sed 's/\.jpg$/\.eps/'`
  echo "$f -> $g" 1>&2
  jpegtopnm $f | pnmtops > $g
done
reinierpost
  • 7,591
  • 1
  • 32
  • 66
0

I do this often and sometimes on Windows. Hence, I wrote a small online converter which uses convert:

JPG to EPS Converter.

Hope this can also help others.

ericzma
  • 693
  • 3
  • 7
  • 22
0

ImageMagick's convert can do that for you.

gspr
  • 10,367
  • 3
  • 38
  • 68