I will be processing hundreds of postscript files and converting them into PNG files with Ghostscript, so I am trying to find a way to batch process them in one command.
When doing this manually I simply do
gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=png16m -r900 -GraphicsAlphaBits=4 -sOutputFile=output.png input.ps
And this works fine. But it's not practical to be doing this for hundreds of files, so I am trying to find a way to input all files within a folder, ending in _rss.ps, into Ghostscript to convert to PNGs.
When I use
#!/bin/bash
for i in *_rss.ps ; do echo "gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=png16m -r900 -GraphicsAlphaBits=4 -sOutputFile=${i/_rss.ps/_rss.png} $i" ; done
It gives the exact result I need
gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=png16m -r900 -dGraphicsAlphaBits=4 -sOutputFile=32532q_rss.png 32532q_rss.ps
gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=png16m -r900 -dGraphicsAlphaBits=4 -sOutputFile=4323_rss.png 4323_rss.ps
gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=png16m -r900 -dGraphicsAlphaBits=4 -sOutputFile=54735_rss.png 54735_rss.ps
gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=png16m -r900 -dGraphicsAlphaBits=4 -sOutputFile=JF290489_rss.png JF290489_rss.ps
but when I remove echo and the quotation marks it gives the following error
GPL Ghostscript 9.25 (2018-09-13)
Copyright (C) 2018 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Error: /syntaxerror in (binary token, type=137)
Operand stack:
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 2047 1 3 %oparray_pop 2046 1 3 %oparray_pop 2026 1 3 %oparray_pop 1884 1 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push
Dictionary stack:
--dict:953/1684(ro)(G)-- --dict:0/20(G)-- --dict:77/200(L)--
Current allocation mode is local
GPL Ghostscript 9.25: Unrecoverable error, exit code 1
Can anyone advise me on what I am doing wrong, or an alternative way to do this?
$iin theforloop cmd execution . Good luck.-dGraphicsAlphaBits=4with ad?