@echo off
set res=72
set size=a5quer
set gsroot=d:\gstools
set gspath=d:\gstools\gs6.01
set boot=C:
if "%1"=="" goto usage  
if "%2"=="" goto usage
if "%3"=="" goto usage
if "%4"=="" goto usage
if "%5"=="" goto usage
if "%3"=="color" set device=jpeg 
if "%3"=="mono" set device=jpeggray
if "%4"=="72" set res=72
if "%4"=="300" set res=300
if "%res%"=="72" goto low
if "%5"=="portrait" set size=-g2250x1687
if "%5"=="landscape" set size=-g2460x3125
if "%5"=="a4" set size=-g2480x3508
if "%5"=="a5quer" set size=-g2480x1754
if not "%5"=="custom" goto export
if "%6"=="" goto usage
if "%7"=="" goto usage
set size=-g%6x%7 
goto export
:low
if "%5"=="portrait" set size=-g540x405
if "%5"=="landscape" set size=-g590x750
if "%5"=="a4" set size=-g595x842
if "%5"=="a5quer" set size=-g595x421
if not "%5"=="custom" goto export
if "%6"=="" goto usage
if "%7"=="" goto usage
set size=-g%6x%7 
:export
set oldpath=%path%
set path=%gspath%\bin;%path%;
set gs_lib=%gspath%\lib;%boot%\psfonts;%gsroot%\fonts; 
@gsos2 -q -dNOPAUSE -sDEVICE=%device% -dJPEGQ=85 %size% -r%res% -sOutputFile=%2 %1 -c quit
set path=%oldpath%
goto ende
:usage
echo Usage: ps2jpeg [Inputfile (*.ps)] [Outputfile (*.jpg)] [mono/color] [72/300] 
echo                [portrait/landscape/a4/a5quer/custom] [[size_x]] [[size_y]]
echo Output: JPEG-packed bitmap, 72x72 dpi or 300x300 dpi.
:ende
