Error "Invalid Parameter" fom ImageMagick convert on Windows
Asked Answered
S

7

35

I am trying to convert a PDF document into a PNG file using ImageMagick command line tools from a ASP.NET website. I create a new shell process and ahve it execute the following command:

convert -density 96x96 "[FileNameAndPath].pdf" "[FileNameAndPath].png"

This runs well when testing the website on my local machine with the ASP.NET Develeopment Server of VS and the command also works well when manually entered into the shell. When running from the programatically created shell in ASP.NET there is the following error message:

Invalid Parameter - 96x96

Does anybody know why that happens and what to do?

I have tested the command while being logged in on the server via RDP with a different user account than the ASP.NET process. I have used exactly the same ImageMagick and Ghostscript installation files as on my local machine and have activated adding the ImageMagick installation path to the enironment variables during installing. The server has not been rebooted since than.

Spreadeagle answered 17/6, 2010 at 8:56 Comment(4)
Can you show the full command line that doesn't work please? (With real life file names)Pokelogan
And are you sure you can call the ghostscript executable from the programmatically created shell?Pokelogan
The complete command line is convert -density 96x96 "C:\inetpub\wwwroot\UserData\Pdf\f18196da-571c-45a6-b99b-615fb3edb454.pdf" "C:\inetpub\wwwroot\UserData\Pdf\f18196da-571c-45a6-b99b-615fb3edb454.png" I thought convert would call gs when the input format was PDF and convert worked from the shell prompt. I did not test that.Spreadeagle
I was getting the "invalid parameter" error because I was placing a different command into a batch script which -fuzz 1% uses a percentage argument, so I needed another percent symbol to get it to parse correctly e.i. -fuzz 1%%.Haematopoiesis
P
76

convert is also the name of a windows executable which converts FAT filesystem to NTFS. When you do not specify the full path of an executable, quote:

...the system first searches the current working directory and then searches the path environment variable, examining each directory from left to right, looking for an executable filename that matches the command name given.

"C:\Windows\System32" is generally present in the beginning of %PATH% variable, causing the Windows convert utility to launch, which fails with "Invalid Parameter" error as expected.

Try specifying the full path of the ImageMagick's convert.exe like so:

"C:\Program Files\ImageMagick\convert.exe" -density 96x96 "path_and_filename.pdf" "path_and_filename.png"
Parboil answered 27/1, 2012 at 15:37 Comment(3)
my C:\Program Files\ImageMagick\ does not contain a convert.exe. Does anyone know what exe to point to in new builds of imagemagic?Christlike
I just installed the latest version and it looks like it's called 'magick.exe'.Waylay
In recent versions you have to add magick before convert e.g. magick convert -density 96x96 "[FileNameAndPath].pdf" "[FileNameAndPath].png"Ferment
R
23

As others have stated convert points to a different program in your PATH. Instead preface your command with magick. So your command would instead be:

magick convert -density 96x96 "[FileNameAndPath].pdf" "[FileNameAndPath].png"
Raymund answered 15/2, 2018 at 20:53 Comment(1)
magick convert is incorrect syntax for ImageMagick 7. Use magick only and not magick convert and not convert. The latter two will give IM 6 behaviorDupont
E
6

In Window actually exists a "convert.exe" in system32 - make sure your script doesn't start that one (maybe the environment paths on your development machine are set differently).

Elo answered 21/6, 2010 at 7:55 Comment(0)
B
5

I am only answering this late because imagemagick was updated. Now, if you wish to use the "convert" command, you do it like this:

magick convert "image.png" "document.pdf"

or

magick convert "image_00*.png" "document.pdf"

for multiple images.

Same syntax for command, just add magick before it

Bengaline answered 9/1, 2019 at 9:6 Comment(1)
magick convert is incorrect syntax for ImageMagick 7. Use magick only and not magick convert and not convert. The latter two will give IM 6 behaviorDupont
D
2

A couple more options for fixing this:

  • Edit your Path system variable to contain the path to imagemagick as it's first content and then add the rest after it. This will make windows always find the imagemagic convert first before it finds the other convert program. So something like this: C:\Program Files\ImageMagick-6.9.2-Q16;C:\Program Files\Haskell Platform\2014.2.0.0\lib\extralibs\bin;...

  • Another option is to create a dedicated folder somewhere on your machine where you will place shortcuts for some of these name clashes. Then what you do is that you rename those shortcuts to meaningful names, for example convert_image_magick, then add the path to this folder to your system path. So now as you hit tab more, you will finally find the right program you want to run

Deliverance answered 16/8, 2015 at 8:37 Comment(0)
E
1

yes! if you launch an Administrator command window it defaults to C:\windows\sytem32\ ... as long as you're not in that directory the command will pickup the ImageMagick convert.exe

My issue was I was using the "FORFILES" command which is tricky because it requires using "cmd /c" and passing the convert command with @path and @file parameters and it does some escaping of slashes... needless to say it's caused me hours and hours of headache. It even parses hex characters, like if your filepath has the combination 0x00 in it, it will think that's a hex value and mangle your path. I had a filepath named C:\ImageRes3000x3000 and FORFILES interprets that literally and it caused a strange path issue. Sorry if this is a long useless post but it's meant to be FYI, if someone runs across this, maybe it will help them. That being said, FORFILES and "convert.exe" are a powerful and simple image renaming line script combo.

here's my full 3 line image renaming script

robocopy D:\SRC_DIR\ D:\DEST_DIR\_staging *.jpg /e /MAXAGE:2
FORFILES /P D:\DEST_DIR\_staging\ /S /M *.jpg /C "cmd /c convert.exe @path -quality 65 -resize 1500 D:\RESIZED_DIR\\@file"
DEL D:\DEST_DIR\_staging\*.* /S /Q
Eliath answered 17/8, 2012 at 22:55 Comment(1)
Path of your script ? Path Windows system ? cmd /c will be C:\windows\sytem32 path ? Where installation path ImageMagick ? have you more scripts working using ImageMagick in the same path?Dolomite
T
0

In 2024 replace convert with

"C:\Program Files\ImageMagick-7.1.1-Q16-HDRI\magick.exe"

Twomey answered 18/6, 2024 at 14:45 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.