我想创建一个验证码图片使用转换从ImageMagick。

我也这么做了,但是有一些问题。

在我的linux shell:

convert -background white -fill black -font FreeSerif-Bold -pointsize 36 label:'adfgh' ./test.png

错误是:

adfgh @ error/constitute.c/ReadImage/453 转换:缺少一个图像文件名。/test.png @ 错误/ convert.c / ConvertImageCommand / 3015

我的ImageMagick:版本:6.7.2-7,我安装它yum install ImageMagick。

我笨。有什么建议吗?


当前回答

我在尝试将pdf转换为jpg时出现了这个错误,并使用以下方法解决了这个问题: sudo vi /etc/ imagemagick */policy.xml

变化:

策略域=“编码器” 权限=“无” 模式=“PDF”

to:

policy domain="coder" rights="read|write" pattern="PDF"

来源:http://realtechtalk.com/imagemagick_convert_pdf_not_authorized - 2217的文章

其他回答

投票最高的答案(我没有足够的声誉在那里添加评论)建议注释掉MVG行,但请记住这一点:

CVE-2016-3714 ImageMagick supports ".svg/.mvg" files which means that attackers can craft code in a scripting language, e.g. MSL (Magick Scripting Language) and MVG (Magick Vector Graphics), upload it to a server disguised as an image file and force the software to run malicious commands on the server side as described above. For example adding the following commands in a file and uploading it to a webserver that uses a vulnerable ImageMagick version will result in running the command "ls -la" on the server. exploit.jpg: push graphic-context viewbox 0 0 640 480 fill 'url(https://website.com/image.png"|ls "-la)' pop graphic-context

And

任何低于7.0.1-2或6.9.4-0的版本都有潜在的漏洞 受影响的各方应尽快升级到最新版本 ImageMagick版本。

如果您不需要通过同一工具处理光栅文件和PDF/PS/EPS,请不要放松ImageMagick的安全性。

相反,保持你的web应用程序完整的防御深度,检查你的Ghostscript已经为所有已知的-dSAFER漏洞打了补丁,然后直接调用它。

gs -dSAFER -r300 -sDEVICE=png16m -o document-%03d.png document.pdf

-dSAFER opts you out of the legacy-compatibility "run Postscript will full permission to interact with the outside world as a turing-complete programming language" mode. -r300 sets the desired DPI to 300 (the default is 72) -sDEVICE specifies the output format (See the Devices section of the manual for other choices.) -o is a shorthand for -dBATCH -dNOPAUSE -sOutputFile= This section of the Ghostscript manual gives some example formats for for multi-file filename output but, for the actual syntax definition, it points you at the documentation for the C printf(3) function.

如果你渲染EPS文件,添加-dEPSCrop,这样它就不会填充你的输出到页面大小,并使用-sDEVICE=pngalpha来获得透明的背景。

我也有错误error/constitute.c/ReadImage/453时,试图转换eps与图像魔术gif。我尝试了sNICkerssss提出的解决方案,但仍然有错误(尽管与第一个不同)e error/ construct .c/ReadImage/412 解决这个问题的方法是将read放到其他条目中

 <policy domain="coder" rights="read" pattern="PS" />
 <policy domain="coder" rights="read" pattern="EPS" />
 <policy domain="coder" rights="read" pattern="PDF" />
 <policy domain="coder" rights="read" pattern="XPS" />
 <policy domain="coder" rights="read|write" pattern="LABEL" />

如果有人需要在安装后用一个命令来完成,运行这个!

sed -i 's/<policy domain="coder" rights="none" pattern="PDF" \/>/<policy domain="coder" rights="read|write" pattern="PDF" \/>/g' /etc/ImageMagick-6/policy.xml

在我的Ubuntu 16.04系统最近更新后,我也开始得到这个错误时,试图运行转换。ps文件转换成pdf。

这个方法对我很有效:

在终端运行中:

sudo gedit /etc/ImageMagick-6/policy.xml

这将在gedit文本编辑器中打开policy.xml文件。如果没有,你的图像魔法可能被安装在不同的地方。 然后改变

rights="none" 

to

rights="read | write" 

PDF, EPS和PS行接近文件底部。保存并退出,然后图像魔法应该再次工作。