简体   繁体   中英

How can I change the dpi of an image in PythonMagick?

I am using images for ocr and I need to change the dpi as part of pre-processing.

import PythonMagick

img_file = 'my_image.jpg'
img = PythonMagick.Image(file)
img.density("600") # It does not seem to work
img.write(img_file + '.tif')

I could call ImageMagick but I would rather use PythonMagick.

I came across a similar problem. With help form other blogs and sites, i came up with a solution.

import PythonMagick

img_file = 'my_image.jpg'
img = PythonMagick.Image()
img.density("600")
img.read(file) #read it at 600 dpi
img.write(img_file + '.tif')

The problem here is to read it at 600dpi before writing it. This should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM