33

Is there any way to convert image formats from Ubuntu terminal?

Particularly from eps to png/jpg or to any other formats.

Zanna
  • 69,223
  • 56
  • 216
  • 327
Sooraj S
  • 1,101
  • 2
  • 16
  • 29

3 Answers3

29

For anyone who lands here trying to figure out how to work around ImageMagic's convert: not authorized without reverting the change that was made to the system-wide security policy to close a vulnerability, here's how to rasterize EPS files by calling Ghostscript directly:

gs -dSAFER -dBATCH -dNOPAUSE -dEPSCrop -r600 -sDEVICE=pngalpha -sOutputFile=foo.png myfile.eps
  • -dSAFER puts Ghostscript in a sandboxed mode where Postscript code can only interact with the files you specified on the command line. (Yes, the parts of EPS, PS, and PDF files that define the page contents are in a turing-complete programming language.)
  • -DBATCH causes it to quit when it reaches the end of the input file, rather than switching to an interactive PostScript prompt.
  • -dNOPAUSE prevents it from prompting to continue after each page
  • -dEPSCrop asks for the rendered output to be cropped to the bounding box of the drawing rather than padded out to the declared page size (See the manual for details.)
  • The -r600 specifies the DPI you want to render at
  • The -sDEVICE specifies the output format (See the Devices section of the manual for other choices.)

UPDATE: I've since learned that -o foo.png is a cleaner, easier-to-remember shorthand for -dBATCH -dNOPAUSE -sOutputFile=foo.png so the better command would be this:

gs -dSAFER -dEPSCrop -r600 -sDEVICE=pngalpha -o foo.png myfile.eps

The manual also mentions that, some day, they eventually hope to be able to make -dSAFER the default though, given backwards compatibility needs, who knows if that will ever happen.

ssokolow
  • 2,188
  • 19
  • 23
29

You can use the imagemagick command line tool

http://www.imagemagick.org/script/convert.php

You can use it like this:

convert myfile.eps foo.png
Zanna
  • 69,223
  • 56
  • 216
  • 327
Piotr Dajlido
  • 422
  • 4
  • 7
  • 15
    I suggest to use the `-density` option also, e.g. `convert -density 150 myfile.eps foo.png`. The default density is only 72 dpi, which looks chunky. – Sam Watkins May 15 '17 at 05:52
  • 1
    Also `mogrify` command is useful, instead `convert`. See `man mogrify` or search on Askubuntu – okoloBasii Jun 14 '17 at 17:49
  • 4
    `convert-im6.q16: attempt to perform an operation not allowed by the security policy PDF @ error/constitute.c/IsCoderAuthorized/408.` - you will need to read this to overcome it https://stackoverflow.com/a/53180170/2324000 – jaromrax Apr 23 '21 at 16:13
0

I convert .odg to .png by using Prt Scr key on keyboard then selecting the area I want to convert. Fast & Safe.

Ted O.
  • 1
  • 1