How to reduce wand memory usage?

前端 未结 4 1669
南方客
南方客 2021-01-13 09:36

I am using wand and pytesseract to get the text of pdfs uploaded to a django website like so:

image_pdf = Image(blob=read_pdf_file, resolution=300)
image_png         


        
4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-13 09:57

    I run into a similar issue.

    Found this page interesting: http://www.imagemagick.org/script/architecture.php#tera-pixel

    And how to limit the amount of memory used by ImageMagick through wand: http://docs.wand-py.org/en/latest/wand/resource.html

    Just adding something like:

    from wand.resource import limits
    
    # Use 100MB of ram before writing temp data to disk.
    limits['memory'] = 1024 * 1024 * 100
    

    It may increase the computation time (but like you, I don't mind too much) and I actually did not notice so much difference.

    I confirmed using Python's memory-profiler that it is working as expected.

提交回复
热议问题