Windows 上 ImageMagick 转换的错误“无效参数”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3060205/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error "Invalid Parameter" fom ImageMagick convert on Windows
提问by rs.
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:
我正在尝试使用来自 ASP.NET 网站的 ImageMagick 命令行工具将 PDF 文档转换为 PNG 文件。我创建了一个新的 shell 进程并执行以下命令:
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:
当使用 VS 的 ASP.NET 开发服务器在我的本地机器上测试网站时,这运行良好,并且当手动输入 shell 时,该命令也运行良好。从 ASP.NET 中以编程方式创建的 shell 运行时,出现以下错误消息:
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.
我在使用与 ASP.NET 进程不同的用户帐户通过 RDP 登录到服务器时测试了该命令。我使用了与本地机器上完全相同的 ImageMagick 和 Ghostscript 安装文件,并在安装过程中激活了将 ImageMagick 安装路径添加到环境变量的功能。从那时起服务器就没有重新启动过。
回答by Salman A
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:
convert
也是将 FAT 文件系统转换为 NTFS 的 Windows 可执行文件的名称。当您不指定可执行文件的完整路径时,引用:
...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 Windowsconvert utility to launch, which fails with "Invalid Parameter" error as expected.
“C:\Windows\System32”通常出现在 %PATH% 变量的开头,导致Windows转换实用程序启动失败,并出现“无效参数”错误。
Try specifying the full path of the ImageMagick's convert.exe like so:
尝试指定 ImageMagick 的 convert.exe 的完整路径,如下所示:
"C:\Program Files\ImageMagick\convert.exe" -density 96x96 "path_and_filename.pdf" "path_and_filename.png"
回答by dagrha
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:
正如其他人所说,convert
指向您的 PATH 中的不同程序。而是用magick
. 所以你的命令应该是:
magick convert -density 96x96 "[FileNameAndPath].pdf" "[FileNameAndPath].png"
回答by Olaf
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).
在 Window 中实际上在 system32 中存在一个“convert.exe”——确保你的脚本没有启动那个(可能你的开发机器上的环境路径设置不同)。
回答by Recessive
I am only answering this late because imagemagick was updated. Now, if you wish to use the "convert" command, you do it like this:
我之所以这么晚才回答,是因为 imagemagick 已更新。现在,如果你想使用“转换”命令,你可以这样做:
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
命令的语法相同,只需magick
在它之前添加
回答by smac89
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 imagemagicconvert
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
编辑您的
Path
系统变量以包含 imagemagick 的路径作为它的第一个内容,然后在其后添加其余内容。这将使 Windowsconvert
在找到其他转换程序之前总是先找到 imagemagic 。所以像这样:C:\Program Files\ImageMagick-6.9.2-Q16;C:\Program Files\Haskell Platform\2014.2.0.0\lib\extralibs\bin;...
另一种选择是在您的机器上的某处创建一个专用文件夹,您将在其中放置一些名称冲突的快捷方式。然后你要做的是将这些快捷方式重命名为有意义的名称,例如
convert_image_magick
,然后将此文件夹的路径添加到您的系统路径中。所以现在当你更多地点击 Tab 时,你最终会找到你想要运行的正确程序
回答by rojomisin
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
是的!如果您启动管理员命令窗口,它默认为 C:\windows\sytem32\ ...只要您不在该目录中,该命令就会选择 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.
我的问题是我使用的是“FORFILES”命令,这很棘手,因为它需要使用“cmd / c”并使用@path 和@file 参数传递转换命令,并且它会进行一些斜杠转义......不用说它是造成的我几个小时的头痛。它甚至会解析十六进制字符,比如如果您的文件路径中包含组合 0x00,它会认为这是一个十六进制值并破坏您的路径。我有一个名为C:\ImageRes3000x3000
FORFILES的文件路径 ,从字面上解释它并导致了一个奇怪的路径问题。对不起,如果这是一个长而无用的帖子,但它的意思是仅供参考,如果有人遇到这个,也许它会帮助他们。话虽如此,FORFILES 和“convert.exe”是一个强大而简单的图像重命名行脚本组合。
here's my full 3 line image renaming script
这是我完整的 3 行图像重命名脚本
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