0

enter image description here

I'm trying to convert some PDFs to jpegs using imagemagick . I'm working on win 10, 64 with python 3.62 - 64 bit and wand 0.4.4. I've been able to get wand working with ImageMagick-6.9.9-Q16-HDRI. I've set the Path and MAGICK_HOME env vars to

E:\ImageMagick-6.9.9-Q16-HDR

This allow:

from wand.image import Image

to work.

My script:

import os
magick_home=os.getcwd() + os.sep + "E:\ImageMagick-6.9.9-Q16-HDR"
os.environ["PATH"] += os.pathsep + magick_home + os.sep
os.environ["MAGICK_HOME"] = magick_home
os.environ["MAGICK_CODER_MODULE_PATH"] = magick_home + os.sep + "modules" + os.sep + "coders"

from wand.image import Image

.....

file_path = os.path.dirname(os.path.abspath(__file__))+os.sep+"myfile.pdf"

image_pdf = Image(filename=file_path, resolution=300)
image_jpeg = image_pdf.convert('jpeg')

I'm getting:

  File "ocr_test.py", line 38, in <module>
    image_pdf = Image(filename=file_path, resolution=300)
  File "e:\Myenv\lib\site-packages\wand\image.py", line 2744, in __init__
    self.read(filename=filename, resolution=resolution)
  File "e:\Myenv\lib\site-packages\wand\image.py", line 2822, in read
    self.raise_exception()
  File "e:\Myenv\lib\site-packages\wand\resource.py", line 222, in raise_exception
    raise e
wand.exceptions.MissingDelegateError: no decode delegate for this image format `PDF' @ error/constitute.c/ReadImage/504

How can I get this working?

EDIT:

Following your advice, I followed https://glenbambrick.com/2017/01/10/pdf-to-jpg-conversion-with-python-for-windows/ and installed ghostscript 9.22 - 32 bit. (I understand that the 64 bit won't work PythonMagick can't find my pdf files) I've set both Path and MAGICK_HOME env vars to contain:

E:\ImageMagick-6.9.9-Q16-HDR;E:\gs9.22\bin

I ran:

$ E:/ImageMagick-6.9.9-Q16-HDRI/convert --version
Version: ImageMagick 6.9.9-23 Q16 x64 2017-11-12 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Visual C++: 180040629
Features: Cipher DPC HDRI Modules OpenMP
Delegates (built-in): bzlib cairo flif freetype jng jp2 jpeg lcms lqr openexr pangocairo png ps raw rsvg tiff webp xml zlib

I don't see gs or gslib. What should I do next?

user1592380
  • 34,265
  • 92
  • 284
  • 515
  • Imagemagick needs Ghostscript as a delegate library to read PDF files. Be sure you have Ghostscript installed where ImageMagick can find it. Often you can tell if you do by `convert -version` and you should see gs or gslib listed as delegates. – fmw42 Nov 28 '17 at 18:46
  • Please see my edit – user1592380 Nov 29 '17 at 16:42
  • gs or gslib is not listed in your delegates. That likely means that ImageMagick cannot find Ghostscript. To be sure it is not there try `convert -list configure` and see if it gs or gslib is listed on the line starting with DELEGATES. If not, then perhaps your install of either Ghostscript or ImageMagick was not correct? I would start over and when installing check to see there are no errors listed when installing Ghostscript or ImageMagick. You can check the config.log files. – fmw42 Nov 29 '17 at 18:01

1 Answers1

0

I don't know if this will help anybody, but for me MAGICK_HOME does not appear to be recognized by windows. I ended up putting :

E:/gs/bin 

at the beginning of My PATH env var, and things started working.

user1592380
  • 34,265
  • 92
  • 284
  • 515