我有一个程序,我需要使用Image Magick将PDF转换为图像.我这样做是使用subprocess包:
cmd = 'magick convert -density 300 '+pdfFile+'['+str(rangeTuple[0])+'-'+str(rangeTuple[1])+'] -depth 8 '+'temp.tiff' #WINDOWS
if(os.path.isfile('temp.tiff')):
os.remove('temp.tiff')
subprocess.call(cmd,shell=True)
im = Image.open('temp.tiff')
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
convert-im6.q16: not authorized `temp2.pdf' @ error/constitute.c/ReadImage/412.
convert-im6.q16: no images defined `temp.tiff' @ error/convert.c/ConvertImageCommand/3258.
Traceback (most recent call last):
File "UKExtraction2.py", line 855, in <module>
doItAllUpper("A0","UK5.csv","temp",59,70,"box",2,1000,firstPageCoordsUK,boxCoordUK,voterBoxCoordUK,internalBoxNumberCoordUK,externalBoxNumberCoordUK,addListInfoUK)
File "UKExtraction2.py", line 776, in doItAllUpper
doItAll(tempPDFName,outputCSV,2,pdfs,formatType,n_blocks,writeBlockSize,firstPageCoords,boxCoord,voterBoxCoord,internalBoxNumberCoord,externalBoxNumberCoord,addListInfo,pdfName)
File "UKExtraction2.py", line 617, in doItAll
mainProcess(pdfName,(0,noOfPages-1),formatType,n_blocks,outputCSV,writeBlockSize,firstPageCoords,boxCoord,voterBoxCoord,internalBoxNumberCoord,externalBoxNumberCoord,addListInfo,bigPDFName,basePages)
File "UKExtraction2.py", line 542, in mainProcess
im = Image.open('temp.tiff')
File "/home/rohit/.local/lib/python3.6/site-packages/PIL/Image.py", line 2609, in open
fp = builtins.open(filename, "rb") …Run Code Online (Sandbox Code Playgroud) 我正在本地 ubuntu 20.04 机器上运行一个 laravel 项目,该项目在另一台机器上运行良好。该项目使用 Image Magic 将 PDF 转换为 PNG。当我调用将 PDF 转换为 PNG 的功能时,出现以下错误:
ImagickException 尝试执行安全策略“PDF”不允许的操作@ error/constitute.c/IsCoderAuthorized/408
该函数看起来:
public function show($id)
{
$book = Book::all()->first();
$file = public_path('' . $book->pdf);
$count = 0;
$im = new \Imagick($file);
$blobList=[];
do {
$page = new \Imagick();
$page->setResolution(300,300);
$page->readImage($file . '['.$count.']');
$page->setImageFormat("jpeg");
header("Content-Type: image/jpeg");
$image = $page->getImageBlob();
array_push($blobList,$image);
$count++;
} while (5> $count);
// $im->resizeImage(200,200,1,0);
return view('notice/showbook', compact('book', 'blobList'));
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,我已经安装了 image magic 和 gs,并policymap.xml参考这个问题的接受答案进行了更改
然而,错误仍然存在。请帮忙!
谢谢,
这似乎与我之前的问题有关,其中存在ghostscript 错误,因此 ImageMagick 开发人员制定了阻止 PDF 转换的安全策略。通过调整策略文件,将权限从“无”(默认情况下)更改为“读取 | 写入”来克服这一问题
我的类似问题是在运行表单命令时启动的
convert input.pdf output.jpg
Run Code Online (Sandbox Code Playgroud)
现在使用 ghostscript 版本 9.27 (2019-04-04) 和 imagemagick 版本 7.0.8-56 Q16 x86_64 (2019-07-21)(我相信这是每个版本的最新版本),我收到此错误
convert: attempt to perform an operation not allowed by the security policy `gs' @ error/delegate.c/ExternalDelegateCommand/378.
convert: no images defined `output.jpg' @ error/convert.c/ConvertImageCommand/3273.
Run Code Online (Sandbox Code Playgroud)
所以我已经 sudoedited/etc/ImageMagick-7/policy.xml使得 中唯一未注释的行<policymap>从
<policy domain="delegate" rights="none" pattern="gs" />
Run Code Online (Sandbox Code Playgroud)
到
<policy domain="coder" rights="read | write" pattern="PDF" />
<policy domain="delegate" rights="read | write" pattern="gs" />
Run Code Online (Sandbox Code Playgroud)
但问题仍然存在。如果简单地注释掉或删除上面的行,则结果相同。这可以在我的不止一台 Arch 机器上重现。 …
使用linux命令行将PDF转换为(单个)JPEG的快速可靠方法是什么?
我目前正在将我的“旧”基于 Python 的聊天机器人重写为 golang。我遇到的一个问题是我无法将 PDF 转换为 jpeg。我想这样做,这样我就可以轻松地将其发送到聊天中。
已经用 bimg(根本不起作用)和 imagemagick (gopkg.in/gographics/imagick.v3/imagick) 尝试过这个,如另一个线程的答案中提供的:“ /sf/answers/3326441751/ ”
imagick.Initialize()
defer imagick.Terminate()
mw := imagick.NewMagickWand()
defer mw.Destroy()
mw.ReadImage(pdf)
mw.SetIteratorIndex(0) // This being the page offset
mw.SetImageFormat("jpg")
mw.WriteImage(image)
Run Code Online (Sandbox Code Playgroud)
它根本不产生 jpg,它只是给我错误
ERROR_POLICY: attempt to perform an operation not allowed by the security policy `PDF' @ error/constitute.c/IsCoderAuthorized/408
Run Code Online (Sandbox Code Playgroud)
我怎样才能使这项工作?我似乎无法为此编辑安全设置。
任何帮助表示赞赏!
我尝试使用 ImageMagick 将 PDF 转换为图像,但出现以下错误:
Convert-im6.q16:尝试执行安全策略“PDF”不允许的操作@ error/constitute.c/IsCoderAuthorized/408。
Convert-im6.q16:没有定义图像“tmp/%03d.png”@ error/convert.c/ConvertImageCommand/3258。
我找到了一堆建议修改policy.xml文件的答案(比如this和this );我的问题是,我不知道在 WSL 上哪里可以找到该文件:我尝试在 /etc/ 中查找它,在 Windows 中进行查找和搜索,但无济于事。知道如何在 WLS 上解决这个问题吗?
是否可以使用 TYPO3 的图像处理工具在 TYPO3 后端裁剪图像,以便cropVariants在前端也使用 PDF 文件?
图像处理工具仅显示消息:
无法确定图像尺寸。
无法提供图像处理,因为图像的原始尺寸未知。
也许我需要另一个服务器端模块?但我无法找到有关此主题的任何信息。