我想通过convertImageMagick 创建一个验证码pic .
我遵循这个,但有一些问题.
输入在我的linux shell中:
convert -background white -fill black -font FreeSerif-Bold -pointsize 36 label:'adfgh' ./test.png
Run Code Online (Sandbox Code Playgroud)
错误是:
转换:未授权
adfgh@ error/construct.c/ReadImage/453.转换:缺少图像文件名./test.png@ error/convert.c/ConvertImageCommand/3015
我的ImageMagick:版本:6.7.2-7,我安装它yum install ImageMagick.
我很无能为力.有什么建议吗?
我有一个程序,我需要使用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) 尝试从本地文件系统加载 PDF 并收到“未授权”错误。
“文件“/env/local/lib/python3.7/site-packages/wand/image.py”,第 4896 行,在读取 self.raise_exception() 文件“/env/local/lib/python3.7/site- package/wand/resource.py", line 222, in raise_exception raise e wand.exceptions.PolicyError: 未授权`/tmp/tmp_iq12nws'@error/constitute.c/ReadImage/412
PDF 文件已从 GCS 成功保存到本地“服务器”,但 Wand 不会加载。将图像加载到 OpenCV 中不是问题,只是在尝试使用 Wand/ImageMagick 加载 PDF 时发生
将 PDF 从 GCS 加载到本地文件系统到 Wand/ImageMagick 的代码如下
_, temp_local_filename = tempfile.mkstemp()
gcs_blob = STORAGE_CLIENT.bucket('XXXX').get_blob(results["storedLocation"])
gcs_blob.download_to_filename(temp_local_filename)
# load the pdf into a set of images using imagemagick
with(Image(filename=temp_local_filename, resolution=200)) as source:
#run through pages and save images etc.
Run Code Online (Sandbox Code Playgroud)
ImageMagick 应该被授权访问本地文件系统上的文件,因此它应该加载文件而不是这个“未授权”错误。