Imagemagick FailedToExecuteCommand `"gswin32c.exe" - imagemagick

I am testing my file conversions on the test server and I got this error below. I tested the case on my local and it worked without a problem. On the server it gives me some trouble.
FailedToExecuteCommand `"gswin32c.exe" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g350x350 -dEPSCrop "-sOutputFile=C:/Windows/TEMP/magick-1520z9_ZtBD3O2dg%d" "-fC:/Windows/TEMP/magick-15203XcyD8hja0LJ" "-fC:/Windows/TEMP/magick-1520fnhOiV0JVLNJ"' (Le fichier spécifié est introuvable.) # error/delegate.c/ExternalDelegateCommand/475.convert:
Any help/tips would be greatly appreciated.
EDIT 2:
I also find a link where the imagemagick admin suggests to change the gs path in the delegates.xml. This solution looks promising but the delegate file has one entry for eps to ps conversions as below:
<delegate decode="eps" encode="ps" mode="bi" command=""#PSDelegate#" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 -sDEVICE=ps2write "-sOutputFile=%o" -- "%i""/>
And I can't seem to find how imagemagick refers to the GS location. I added gs to the path variable and/or modified the delegates.xml with the location to fix this.
EDIT 3:
I have a error "no images defined" from the imagemagick convert command as below. Do I need to set up some permissions for gs because I don't find the temporary folders in the Temp directory.These seems to work magically on my local, but hesitates to function on the test server.
convert: Postscript delegate failed [ghostscript library 9.22] -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g350x350 -dEPSCrop "-sOutputFile=C:/Windows/TEMP/magick-110207SjtG6NIBllO%d" "-fC:/Windows/TEMP/magick-1102057mSI5SPZ919" "-fC:/Windows/TEMP/magick-11020HeIOX7qThedE" -c showpage: (null)' # error/ps.c/ReadPSImage/884.convert: no images definedD:\inetpub\IndependenceAWS\Conversion_DEV_DCHI\78\20190208-121606-797-QSAX2N0OVB\JPG\icam_logo_ToJPG.JPG' # error/convert.c/ConvertImageCommand/3300

For the first problem,
FailedToExecuteCommand `"gswin32c.exe"
Configure the path of the ghostscript bin folder on the system variables and/or configure the delegates.xml which can be found in the folder path C:\Program Files\ImageMagick-7.0.8-Q16
Modify the delegate as below:
delegate decode="eps" encode="ps" mode="bi" command=""C:\Program
Files\gs\gs9.26\bin\gswin64.exe#" -q -dQUIET -dSAFER -dBATCH
-dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 -sDEVICE=ps2write "-sOutputFile=%o" -- "%i""
For the second problem where Imagemagick has problems to access the Temp folder of the C drive.
Add or uncomment the policy for the temporary file path as below
policy domain="resource" name="temporary-path"
value="D:/inetpub/IndependenceAWS/Conversion-Temp"/
Another edit in the same xml as below solves the problems and allows imagemagick to use the new folder for temporary conversions
policy domain="module" rights="read|write" pattern="{PS,PDF,XPS}"
A great thanks to all the people who have commented on my question and helped me solve these issues.

You need to install ghostscript.
You can download it here and install it and the error goes away.
For example, download the 64bit version, and double click it and go by its installation instructions. Then rerun your magick command, the FailedToExecuteCommand "gswin32c.exe" error will go away.
Note: as a comment mentioned: GS 9.26 has some bugs -- try downgrading to 9.23, 9.24 or 9.25. 3, using 9.27 produces neither errors nor output, but after changing to 9.24, all things are fine.

If anyone is having this issue with the MSYS2 build of ImageMagick, you need to install GhostScript through MSYS2: run either of:
on MSYS2 MinGW 64 bits: pacman -S mingw-w64-x86_64-ghostscript
on MSYS2 MinGW 32 bits: pacman -S mingw-w64-i686-ghostscript

Changed gs to full path.
Problem is here....

I know this is an old thread but I'd like to add my experience as it may help someone.
I was getting the same error as you, but for me the issue turned out to be not enough RAM.
This was running on a VM with not much RAM allocated, upgraded to 4GB and everything works great.

Related

Cannot save kable to PDF due to error in magick_image_readpath

I am trying to save a table created in the Kable package in R Markdown. This has always worked for me in the past, but today when I try, using 'save_kable("X.pdf")' on any of my tables, I get the following error message:
Error in magick_image_readpath(enc2native(path), density, depth, strip) :
rsession: FailedToExecuteCommand `'gs' -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 '-sDEVICE=pngalpha' -dTextAlphaBits=4 -dGraphicsAlphaBits=4 '-r72x72' '-sOutputFile=/var/folders/qc/xs3g8dsx4g11rjbt0rf35dj00000gq/T//RtmpaRzbJq/magick-43640eHHAxmi4Z6n5%d' '-f/var/folders/qc/xs3g8dsx4g11rjbt0rf35dj00000gq/T//RtmpaRzbJq/magick-436404K7X59eUrjJR' '-f/var/folders/qc/xs3g8dsx4g11rjbt0rf35dj00000gq/T//RtmpaRzbJq/magick-43640Xy025Mi88F3t'' (1) # error/pdf.c/InvokePDFDelegate/292
I have restarted R Studio and tried again but it doesn't change anything. Does anyone know what this error message means or how to solve it?
I had the same problem. I resolved it by installing GhostScript on the machine.

failed to execute command 'gs' when converting a single page of pdf to jpg in imagemagick

When I am executing the below command (to create thumbnail of a pdf file)
convert -density 300 'image.pdf' -colorspace RGB -resize '100x100^' -gravity north -extent 100x100 'image_thumbnail.jpg
I am getting the below error
convert: FailedToExecuteCommand `'gs' -sstdout=%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 '-sDEVICE=pngalpha' -dTextAlphaBits=4 -dGraphicsAlphaBits=4 '-r72x72' -dFirstPage=1 -dLastPage=1 '-sOutputFile=/tmp/magick-2243905865hWInyt6%d' '-f/tmp/magick-22439X8ArwDDJggvw' '-f/tmp/magick-22439Omw2cAWv3jxW'' (-1) # error/delegate.c/ExternalDelegateCommand/478.
Hi Prashant.
I had such an issue using node-pdf-image package. I had been investigating it for several days before I found the solution.
I tried to update the versions of ImageMagick and GhostScript, but it didn't help.
The only workaround I found was the next one: use GraphicsMagick and invoke the convert prefixed with gm - like gm convert [options].
But of course, this solution was acceptable for my stuff, and it depends on the task.

error message while converting pdf to jpg file

I am trying to convert a PDF file to jpg file, this is what I was doing and the related error message. What are the reasons for this kind of error?
magick convert -density 600 C:\Users\Desktop\temp.pdf C:\Users\Desktop\temp.jpg
convert: FailedToExecuteCommand `"gswin32c.exe" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r600x600" "-sOutputFile=C:/Users/ugwz/AppData/Local/Temp/magick-36562c7WhZLZFMM6%d" "-fC:/Users/ugwz/AppData/Local/Temp/magick-3656VktS46lP2HwZ" "-fC:/Users/ugwz/AppData/Local/Temp/magick-3656xOHiogtkf3t5"' (The system cannot find the file specified.
) # error/delegate.c/ExternalDelegateCommand/459.
convert: PDFDelegateFailed `The system cannot find the file specified.
' # error/pdf.c/ReadPDFImage/796.
convert: no images defined `C:\Users\Desktop\temp.jpg' # error/convert.c/ConvertImageCommand/3275.
To validate the existence of original file location, here is the output
C:\Users\Desktop>dir temp.pdf
Volume in drive C is Global Information Link
Volume Serial Number is 6646-37D4
Directory of C:\Users\Desktop
07/10/2018 01:55 PM 175,108 temp.pdf
1 File(s) 175,108 bytes
0 Dir(s) 12,942,802,944 bytes free

Ghostscript silent printing

I am trying to print pdf file silently from command line (Windows7)and this is what I am using, but I get "gswin32.exe has stopped working." error message.
gswin32c.exe -sDEVICE=mswinpr2 -dBATCH -dNOPAUSE -dNoCancel -sOutputFile="%printer%Samsung M2020 Series" "c:\test.pdf"
I tried the above in other machine, but same result.
The following line prompts the print dialogue box which I don't want.
gswin32c.exe -sDEVICE=mswinpr2 -dBATCH -dNOPAUSE -dNoCancel -sOutputFile=\\spool "c:\test.pdf"
Is it possible to print silently using ghostscript?
thanks,
I installed GSView and this worked:
gsprint -noquery -all -printer "Samsung M2020 Series" "c:\scannedDocOnePage.pdf"
gswin32c.exe -sDEVICE=mswinpr2 -dBATCH -dNOPAUSE -sOutputFile="%printer%Samsung M2020 Series" file.pdf
I was able to get a silent print by removing -sOutputFile and use -dQueryUser=3 instead. This will always print to the default printer set up in control panel though.
"C:\Program Files\gs\gs9.52\bin\gswin64c.exe" -dNORANGEPAGESIZE -dPrinted -dNoCancel -dBATCH -dNOPAUSE -dNOSAFER -q -dNumCopies=1 -dQueryUser=3 -sDEVICE=mswinpr2 "mypdf.pdf"

Imagemagick Convert PDF to JPEG: FailedToExecuteCommand `"gswin32c.exe" / PDFDelegateFailed

I have PDFs that I need to convert to images. I have installed Imagemagick. I have a PDF named a.pdf that I can open (it is not corrupt) in the folder C:\Convert\
From the command line I am trying
C:\Convert>convert a.pdf a.jpg
And I am getting the error.
convert.exe: FailedToExecuteCommand `"gswin32c.exe" -q -dQUIET -dSAFER -dBATCH -
dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEV
ICE=pamcmyk32" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -dUseCIEColor
"-sOutputFile=C:/Users/MNALDO~1.COR/AppData/Local/Temp/magick-3704HYGOqqIK5rhI%d
" "-fC:/Users//MNALDO~1.COR/AppData/Local/Temp/magick-3704vK6aHo7Ju9WO" "-fC:/Use
rs//MNALDO~1.COR/AppData/Local/Temp/magick-3704GQSF9kK8WAw6"' (The system cannot
find the file specified.
) # error/delegate.c/ExternalDelegateCommand/480.
convert.exe: PDFDelegateFailed `The system cannot find the file specified.
' # error/pdf.c/ReadPDFImage/797.
convert.exe: no images defined `a.jpg' # error/convert.c/ConvertImageCommand/323
0.
UPDATE:
After the SO community helped me solve this issue I put together a little tool to batch convert images. Hope it helps somebody.
https://github.com/MattDolan/ImageConverter
You need to install Ghostscript in order to rasterize vector files (PDF, EPS, PS, etc.) with ImageMagick. IM will shell out to Ghostscript when doing these manipulations (you can see it if you use the -verbose tag in your IM invocation). You could also use Ghostscript by itself to rasterize vector files.
Since you actually have to install Ghostscript to do this, why not drop ImageMagick all-together? It just forwards the command to Ghostscript anyway, not adding any value, just taking way longer to process (and loading everything into RAM while its at it).
Install GhostScript and run the command:
gswin64c.exe -dNOPAUSE -sDEVICE=jpeg -r200 -dJPEGQ=60 -sOutputFile=foo-%03d.jpg foo.pdf -dBATCH
This is identical and faster than running:
convert -quality 60 -density 200 foo.pdf foo-%03d.jpg
It's in the docs now. https://github.com/dlemstra/Magick.NET/blob/main/docs/ConvertPDF.md
You need to install the latest version of GhostScript before you can convert a pdf using Magick.NET.
Make sure you only install the version of GhostScript with the same
platform. If you use the 64-bit version of Magick.NET you should also
install the 64-bit version of Ghostscript. You can use the 32-bit
version together with the 64-version but you will get a better
performance if you keep the platforms the same.
Here is a wrapper: https://archive.codeplex.com/?p=ghostscriptnet
I found that I had installed GhostScript, but GhostScript was not able to execute because it needed additional libraries. By typing "gs" on a command line, I was able to see what libraries were missing.
Install GhostScript GNU Affero General Public License from here.

Resources