Search code examples
jpegghostscriptautorotate

Rotate jpeg images in ghostscript


I am converting .ps file to .jpeg file using ghostscript. But the output file should be rotated by 180 degree.

I am using the below command to rotate.

gswin64c.exe -sDEVICE=jpeg -dBATCH -dNOPAUSE -dSAFER -r300x300 -sOutputFile=E:\temp\test.jpg -dEPSCrop -c "<</Orientation 1>> setpagedevice" "E:\temp\myFile.ps.

Its giving below error:

GPL Ghostscript 9.10 (2013-08-30) Copyright (C) 2013 Artifex Software, Inc. All rights reserved. This software comes with NO WARRANTY: see the file PUBLIC for details. Error: /undefined in E:\temp\myFile.ps Operand stack:

Execution stack: %interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-

  • 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- fa lse 1 %stopped_push .runexec2 --nostringval-- --nostringval-- --nost ringval-- 2 %stopped_push --nostringval-- Dictionary stack: --dict:1182/1684(ro)(G)-- --dict:0/20(G)-- --dict:77/200(L)-- Current allocation mode is local Last OS error: No such file or directory GPL Ghostscript 9.10: Unrecoverable error, exit code 1

PS:- E:\temp\myFile.ps location and file exists in my system.


Solution

  • You have started arbitrary PostScript by using the -c switch. From then on everything until the next switch is treated as PostScript.

    Your command line does not include any '-' between the closing " and the input filename, so the input filename is treated as part of the PostScript program. Since there is no PostScript token 'E;\temp\myFile.ps' the interpreter gives you an undefined error.

    Try putting a -f (-f means treat the next thing as a filename) after the "...setpagedevice".

    That said, I'm dubious this will achieve what you want anyway, it depends on what's in the input file. You've used -dEPSCrop yet the filename has a .ps extension. Unless the file is really an EPS then EPSCrop won't have any effect. If it is an EPS then the media size will be the dimensions of the EPS BoundingBox and (I believe) the Orientation will be ignored. If the input file is not an EPS then the EPSCrop will be ignored.

    You are using a very elderly version of Ghostscript (7 years old) you should really update.