ImageMagickを使ってPythonスクリプトからpdfを600dpiのtiff、96dpiのjpgに変換したい。
(imagemagick)コマンドラインを使用してこのタスクを実行しましたが、PythonでImagemagickを使用してpdfをtiffおよびjpgに変換したい、
そのために私を助けてもらえますか......
ImageMagickを使ってPythonスクリプトからpdfを600dpiのtiff、96dpiのjpgに変換したい。
(imagemagick)コマンドラインを使用してこのタスクを実行しましたが、PythonでImagemagickを使用してpdfをtiffおよびjpgに変換したい、
そのために私を助けてもらえますか......
まず、imagemagick ライブラリのラッパーをロードする必要があります
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
subprocess モジュールを使用して imagemagick コマンドを実行できます
import subprocess
params = ['convert', "Options", 'pdf_file', 'thumb.jpg']
subprocess.check_call(params)