title: Wand DelegateError after Reading Several Images
body: <p>I am reading images from a folder and searching the images for a specific pattern using openCV. Unfortunately after a few images I get the wand.exceptions.DelegateError below.  The number of images that are read before the error occurs varies wildly, sometimes it happens after 3 images sometimes after 20.  </p>
  
  <p>Error:</p>
  
  <blockquote>
    <p>File “/usr/local/python3.5/dist-packages/wand/resource.py”, line 222,
    in raise_exception  raise e wand.exceptions.DelegateError:
    FailedToExectuteCommand ‘”gs” -q -dQUIET -dSAFER -dBATCH -dNOPAUSE
    -dNOPRINT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 “-sDEVICE=pngalpha” -dTextAlphaBits=4 “-r500x500”
    “-sOutputFile=/tmp/magick-29605oLlgPbxLwJy%d”
    “-f/tmp/magick-2960EjsrSmTrJxjN” “-f/tmp/magick-2960f8G76Z8ZfzT1”’
    (-1) @error/delegate.c/ExternalDelegateCommand/461</p>
  </blockquote>
  
  <p>I have attempted to run the code from the Terminal rather than through PyCharm as suggested in this post, however the error is still occurring: <a href="https://stackoverflow.com/questions/46141661/wand-and-ghostscript-issue-on-pycharm">Wand and ghostscript issue on PyCharm</a></p>
  
  <p>Here are some specifics for the my system:</p>
  
  <ul>
  <li>Oracle VirtualBox - Ubuntu 16.04</li>
  <li>Python 3.5</li>
  <li>Wand 0.4.4</li>
  <li>ghostscript 9.18 (installed from repo)</li>
  </ul>
  
  <p>Code:</p>
  
  <pre><code>for doc in PDFs:
      d+=1
      print('')
      print('Document:', '(', d, 'of', len(PDFs), ')', doc)
      #Create JPEG object
      image_pdf = Image(filename=path+doc, resolution=500)
      image_jpeg = image_pdf.convert('jpeg')
  
      req_image = list()
  
      #Create list of jpeg blobs for Pattern Scanning
      for img in image_jpeg.sequence:
          image_page = Image(image=img)
          req_image.append(image_page.make_blob('jpeg'))
  
  
      #Loop for processing each image in a PDF
      n=0
      for img in req_image:
          n+=1
  
          image_buffer = np.asarray(bytearray(img), dtype=np.uint8)
          if image_buffer is not None:
              cv_img = cv2.imdecode(image_buffer, cv2.IMREAD_GRAYSCALE)
  </code></pre>
  
  <p>Has anyone experienced this error?  I am confused as to why the process works initially for several documents but seems to randomly generate an error.  </p>
  
  <p>Thanks for your help. </p>