2

I am working on changing pdfs to images using PythonMagick. I am successfully changing the formats, but the quality of the image is diminished during this process.

This is the code that i am using.

sample_pdf="test_pdf"
sample_image="test_image"

pdf='/home/path/'+sample_pdf+''
image='/home/path/images/'+sample_image+''

im = PythonMagick.Image(pdf)
im.write(image)

I am losing the quality of image by this process.

While researching i found that the below code helps in retaining the quality of the image by using ImageMagick

convert -density 300 source.pdf -quality 80 target.jpg

is there something similar in PythonMagick? I cant seem to find any, online.

Thanks in advance.

Harsha Jasti
  • 1,114
  • 1
  • 9
  • 25

2 Answers2

2
import PythonMagick

sample_pdf="test_pdf"
sample_image="test_image"

pdf='/home/path/'+sample_pdf+''
image='/home/path/images/'+sample_image+''

im = PythonMagick.Image()
im.density("300")
im.read(pdf)
im.quality(100)
im.write(image)

This worked like a charm for me. Thanks once again Payet.

Harsha Jasti
  • 1,114
  • 1
  • 9
  • 25
1

Have you tried the density and quality methods of your instance?

sample_pdf="test_pdf"
sample_image="test_image"

pdf='/home/path/{}'.format(sample_pdf)
image='/home/path/images/{}'.format(sample_image)

im = PythonMagick.Image(pdf)
im.density("300")
im.quality(80)
im.write(image)

You should have look at the API documentation.

payet_s
  • 71
  • 3
  • worked for me .. thanks payet. A small doubt though, couldnt find the difference with density of 1000 or 100 value, can you tell me what exactly density does? – Harsha Jasti Jun 22 '16 at 09:42