![](/img/trans.png)
[英]How can I save a figure in tiff with 600 dpi with compression using matplotlib?
[英]convert PDF into TIFF with 600dpi and jpg 96 dpi
我想使用 ImageMagick 從 Python 腳本將 pdf 轉換為 600 dpi 的 tiff 和 96 dpi 的 jpg。
我使用 (imagemagick) 命令行完成了這項任務,但我想在 python 中使用 Imagemagick 將 pdf 轉換為 tiff 和 jpg,
你能幫我嗎......
首先,您必須在 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
可以使用subprocess 模塊執行 imagemagick 命令
import subprocess
params = ['convert', "Options", 'pdf_file', 'thumb.jpg']
subprocess.check_call(params)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.