moneyslow.com

ImageMagic的convert、mogrify命令报错没有权限convert-im6.q16: not authorized `xxx.pdf' @ error/constitute.c/ReadImage/412.

如何删除百度上的公司信息

如何删除百度上的公司信息

用ImageMagic convert命令将*.pdf文件转换为*.pdf文件。收到以下错误:

convert-im6.q16: not authorized `xxx.pdf' @ error/constitute.c/ReadImage/412.

编辑文件/etc/ImageMagick-6/policy.xml

policy domain="coder" rights="none" pattern="PDF"
改为
policy domain="coder" rights="read|write" pattern="PDF"

同样道理,如果遇到以下报错:

mogrify-im6.q16: attempt to perform an operation not allowed by the security policy `@t.txt' @ error/property.c/InterpretImageProperties/3706

也是编辑/etc/ImageMagick-6/policy.xml 这个神奇的文件:

  <policy domain="delegate" rights="none" pattern="URL" />
  <policy domain="delegate" rights="none" pattern="HTTPS" />
  <policy domain="delegate" rights="none" pattern="HTTP" />
  <!-- in order to avoid to get image with password text -->
  <policy domain="path" rights="read|write" pattern="@*"/>
  <!-- disable ghostscript format types -->
  <policy domain="coder" rights="none" pattern="PS" />
  <policy domain="coder" rights="none" pattern="PS2" />
  <policy domain="coder" rights="none" pattern="PS3" />
  <policy domain="coder" rights="none" pattern="EPS" />
  <policy domain="coder" rights="none" pattern="PDF" />
  <policy domain="coder" rights="none" pattern="XPS" />

例如这里是@t.txt 报错,对应的就是修改pattern="@*"这一行,把none改为read|write 。

同样,如果其他例如pdf的报错,Xps的报错,把none改为“read|write”就ok了。

另外,可能会存在多个xml配置文件的问题,怎么样把它全部改掉生效?如何确定使用的是哪个配置文件?

第一种方案:

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

第二种方案:自动获取 policy.xml 文件的位置并对它们全部执行搜索/替换

for file in `convert -list policy | grep "Path:" | grep -v built | sed 's/Path: \(.*\)/\1/g'`; do sed -i 's/domain="coder" rights="none" pattern="PDF"/domain="coder" rights="read|write" pattern="PDF"/g' $file; done

参考:https://askubuntu.com/questions/1081895/trouble-with-batch-conversion-of-png-to-pdf-using-convert

Exit mobile version