title: Wand Python and left over Image Magick files
body: <p>My Python script converts PDF files in images to be used in PyTesseract:</p>
  
  <pre><code>def images(inputFile):
      pdfFile = wi(filename = inputFile, resolution=600)
  
      formato = 'png'
      image = pdfFile.convert(formato)
  
      pag = 0
      dfs = []
  
      for img in image.sequence:
          pag += 1
          img.rotate(90)
  
          # HOCR
          with img[1100:4190, 1150:3080] as cropped: #[left:right, top:bottom]
              imgPage = wi(image = cropped)
              imageBlob = imgPage.make_blob(formato)
              horas = gerarHocr(imageBlob)
  
  def gerarHocr(imageBlob):
      image = Image.open(io.BytesIO(imageBlob))
      markup = pytesseract.image_to_pdf_or_hocr(image, lang='por', extension='hocr')
      soup = BeautifulSoup(markup, features='html.parser')
  
      spans = soup.find_all('span', {'class' : 'ocrx_word'})
  
      listHoras = []
  
      for sp in spans:
          hora = horaMarcada(sp.get('title').split()[1], sp.get('title').split()[2], sp.get('title').split()[3], sp.get('title').split()[4], sp.get_text().split()[0])
          listHoras.append(hora)
  
      return listHoras
  
  images('foo.pdf')
  </code></pre>
  
  <p>After the execution I have a large amount of Magick files in temp folder that the Python didn't delete by itself.</p>
  
  <p>I tried many solutions to stop Wand producing these files:</p>
  
  <p><a href="https://i.stack.imgur.com/evbbQ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/evbbQ.jpg" alt="Magick-*"></a></p>
  
  <p>I changed the <code>&lt;!-- &lt;policy domain="resource" name="disk" value="16EB"/&gt; --&gt;</code> in the <em>policy.xml</em> to </p>
  
  <pre><code>name="disk" value="1GiB"
  </code></pre>
  
  <pre><code>&lt;policymap&gt;
    &lt;!-- &lt;policy domain="resource" name="temporary-path" value="/tmp"/&gt; --&gt;
    &lt;!-- &lt;policy domain="resource" name="memory" value="2GiB"/&gt; --&gt;
    &lt;!-- &lt;policy domain="resource" name="map" value="4GiB"/&gt; --&gt;
    &lt;!-- &lt;policy domain="resource" name="width" value="10MP"/&gt; --&gt;
    &lt;!-- &lt;policy domain="resource" name="height" value="10MP"/&gt; --&gt;
    &lt;!-- &lt;policy domain="resource" name="area" value="1GB"/&gt; --&gt;
    &lt;!-- &lt;policy domain="resource" name="disk" value="1GiB"/&gt; --&gt;
    &lt;!-- &lt;policy domain="resource" name="file" value="768"/&gt; --&gt;
    &lt;!-- &lt;policy domain="resource" name="thread" value="4"/&gt; --&gt;
    &lt;!-- &lt;policy domain="resource" name="throttle" value="0"/&gt; --&gt;
    &lt;!-- &lt;policy domain="resource" name="time" value="3600"/&gt; --&gt;
    &lt;!-- &lt;policy domain="system" name="precision" value="6"/&gt; --&gt;
    &lt;!-- &lt;policy domain="coder" rights="none" pattern="MVG" /&gt; --&gt;
    &lt;!-- &lt;policy domain="delegate" rights="none" pattern="HTTPS" /&gt; --&gt;
    &lt;!-- &lt;policy domain="path" rights="none" pattern="@*" /&gt; --&gt;
    &lt;policy domain="cache" name="shared-secret" value="passphrase" stealth="true"/&gt;
  &lt;/policymap&gt;
  </code></pre>
  
  <p>But didn't work.</p>