Imagemagick安全策略似乎不允许我执行从pdf到png的转换。转换其他扩展似乎是工作的,只是不是从pdf。我没有改变任何imagemagick设置自从我安装它…我使用的是Arch Linux,如果操作系统很重要的话。

user@machine $ convert -density 300 -depth 8 -quality 90 input.pdf output.png
convert: attempt to perform an operation not allowed by the security policy `PDF' @ error/constitute.c/IsCoderAuthorized/408.
convert: no images defined `output.png' @ error/convert.c/ConvertImageCommand/3288.

当前回答

正如某些评论中指出的,您需要在/etc/ImageMagick-7/policy.xml中编辑ImageMagick的策略。更具体地说,在撰写本文时(05/01/2019),在ArchLinux中,以下一行是未注释的:

<policy domain="coder" rights="none" pattern="{PS,PS2,PS3,EPS,PDF,XPS}" />

只要在<!——和——>来注释它,PDF转换应该再次工作。

其他回答

在我的archlinux系统上,这行已经没有注释了。我不得不将“none”替换为“read | write”以使其工作。

曼扎罗 2021 年 4 月

只需删除/etc/ imagemagick -7/policy.xml中<policymap>内未注释的行

嗯,我补充道

  <policy domain="coder" rights="read | write" pattern="PDF" />

就在/etc/ imagemagick -7/policy.xml中的</policymap>之前,这使它再次工作,但不确定这对安全的影响。

谢谢@tanius和其他人的详细回答!

我只想补充以下几点。

策略文件policy.xml的路径可能会随着ImageMagick的版本而改变,如/etc/ImageMagick-6/policy.xml或/etc/ImageMagick-7/policy.xml等。所以要相应地更新它。 由于防止或允许某些文件类型转换的策略是一种安全措施,您可能希望在任务完成后重置对policy.xml的更改,以便如果攻击者可以访问系统,则不存在相应攻击的可能性!

快乐的快速文件转换同时!

对于Arch Linux的我来说,我不得不这样评论:

  <policy domain="delegate" rights="none" pattern="gs" />