Reputation: 21
I want to convert pdf into tiff with 600 dpi and jpg with 96 dpi from Python script using ImageMagick.
i was done this task using (imagemagick) command line but i want to convert pdf into tiff and jpg using Imagemagick in python ,
can you please help me for that......
Upvotes: 2
Views: 11302
Reputation: 5048
First you have to load a wrapper around imagemagick library
using PythonMagick:
from PythonMagick import Image
or using pgmagick:
from pgmagick import Image
then, independently from the library you loaded, the following code will convert and resize the 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
Upvotes: 3
Reputation: 82765
You can use the subprocess module to execute the imagemagick command
import subprocess
params = ['convert', "Options", 'pdf_file', 'thumb.jpg']
subprocess.check_call(params)
Upvotes: 1