2

ImageMagickを使ってPythonスクリプトからpdfを600dpiのtiff、96dpiのjpgに変換したい。

(imagemagick)コマンドラインを使用してこのタスクを実行しましたが、PythonでImagemagickを使用してpdfをtiffおよびjpgに変換したい、

そのために私を助けてもらえますか......

4

2 に答える 2

3

まず、imagemagick ライブラリのラッパーをロードする必要があります

PythonMagick の使用:

from PythonMagick import Image

またはpgmagickを使用:

from pgmagick import Image

次に、ロードしたライブラリとは別に、次のコードは画像を変換してサイズ変更します

img = Image()
img.density('600')  # you have to set this here if the initial dpi are > 72

img.read('test.pdf') # the pdf is rendered at 600 dpi
img.write('test.tif')

img.density('96')  # this has to be lower than the first dpi value (it was 600)
# img.resize('100x100')  # size in px, just in case you need it
img.write('test.jpg')  


# ... same code as with pythonmagick 
于 2013-02-14T06:38:08.413 に答える
1

subprocess モジュールを使用して imagemagick コマンドを実行できます

import subprocess
params = ['convert', "Options", 'pdf_file', 'thumb.jpg']
subprocess.check_call(params)
于 2013-02-14T05:49:07.410 に答える