0
votes

I'm using Python Wand module(version 0.4.3.) to convert an image stored in pdf to PNG. Final PNG quality is great when I saved the final image in its orignal image width and height. But, when I try to save it to smaller image final PNG gets blurry and quality is not that great.

The difference between two images is shown here. Top image is converted to original size (10800x7200px). The second one is scale to 1250x833px.

Is there any way I can improve the second image? I played with different filter and blur setting.But, could not get the image quality I want. Any help is greatly appreciated.

Code I used to convert PDF to png in its original size:

 def pdf_to_png(pdf_name, res):
      with Image(filename=pdf_name,  resolution=res) as img:
           with Image(width=img.width,height=img.height, background=Color("white")) as bg:
                bg.composite(img,0,0)`
                bg.save(filename="Drawing_improved_wand.png")`
 pdf_to_png('Drawing_1.pdf', 300)

Code for resized png:

 with Image(filename="Drawing_1.pdf",  resolution=(300,300)) as img:
      with Image(width=1250, height=833, background=Color("white")) as bg:
           img.resize(1250, 833,filter='undefined', blur=1)
           img.format = 'png'
           bg.composite(img,0,0)
           bg.save(filename='Drawing_improved_wand1250x833.png')
2

2 Answers

0
votes

This is likely due to an inefficiency with how ImageMagick handles rasterization form PDF text + vectors, and not because of anything you're doing wrong. The large PNG likely has the same problems as the small one, but since the resolution is almost an order of magnitude higher, the effects become imperceptible.

If when exporting to the large PNG the file looks good, I would use this for further processing (like scaling down) and not the PDF.

0
votes

have you try to set blur < 1?

for example:

img.resize(1250, 833,filter='undefined', blur=0.1)