どのように私はImageMagickのを使用して、高解像度のJPEGファイルにいくつかのPDFファイルを変換しようとしている
バイナリ文字列からワンドで高解像度のJPEGを作成します。私は10、64のpython 3.62 - 64ビットと0.4.4のwanで作業しています。コマンドラインで私は:
$ /e/ImageMagick-6.9.9-Q16-HDRI/convert.exe -density 400 myfile.pdf -scale 2000x1000 test3.jpg.
私にとってはうまくいきます。 Pythonで
:
私は低解像度のJPEGファイルを与えているfrom wand.image import Image
file_path = os.path.dirname(os.path.abspath(__file__))+os.sep+"myfile.pdf"
with Image(filename=file_path, resolution=400) as image:
image.save()
image_jpeg = image.convert('jpeg')
。同じことをするには、これを私のワンドコードにどのように翻訳すればよいですか?
編集:
私はので、私が試したhttp://docs.wand-py.org/en/0.4.4/guide/read.html#read-blobに基づいて、問題は入力PDFは、バイナリ文字列としてImageオブジェクトに読み込まなければならないことであることに気づい:
with open(file_path,'rb') as f:
image_binary = f.read()
f.close()
with Image(blob=image_binary,resolution=400) as img:
img.transform('2000x1000', '100%')
img.make_blob('jpeg')
img.save(filename='out.jpg')
をこの読み取りファイルはokですが、出力は10個のファイルに分割されています。どうして?私は1つの高解像度jpegにこれを取得する必要があります。
EDIT:
私は、OCR APIにJPEGを送信する必要があるので、私は、オブジェクトのような出力をファイルに書き込むことができれば、私は思っていました。 https://www.imagemagick.org/api/magick-image.php#MagickWriteImageFileを見て、私が試した:
emptyFile = Image(width=1500, height=2000)
with Image(filename=file_path, resolution=400) as image:
library.MagickResetIterator(image.wand)
# Call C-API Append method.
resource_pointer = library.MagickAppendImages(image.wand,
True)
library.MagickWriteImagesFile(resource_pointer,emptyFile)
これが与える:
File "E:/ENVS/r3/pdfminer.six/ocr_space.py", line 113, in <module>
test_file = ocr_stream(filename='test4.jpg')
File "E:/ENVS/r3/pdfminer.six/ocr_space.py", line 96, in ocr_stream
library.MagickWriteImagesFile(resource_pointer,emptyFile)
ctypes.ArgumentError: argument 2: <class 'TypeError'>: wrong type
どのように私はこの作業を得ることができますか?
正確な問題は何ですか?プログラムは何を出力しますか?何を出力したいですか? –